我用DrRacket.我有这个代码的问题:
(define (qweqwe n) (
(cond
[(< n 10) #t]
[(>= (lastnum n) (pochtilastnum n)) (qweqwe (quotient n 10))]
[else #f]
)
)
)
(define ( RTY file1 file2 )
(define out (open-output-file file2 #:mode 'text #:exists 'replace))
(define in (open-input-file file1))
(define (printtofile q) (begin
(write q out)
(display '#\newline out)
))
(define (next)
(define n (read in))
(cond
[(equal? n eof) #t]
[else (begin
((if (qweqwe n) (printtofile n) #f))
) (next)]
)
)
(next)
(close-input-port in)
(close-output-port out))
Run Code Online (Sandbox Code Playgroud)
但是当我开始时(RTY"in.txt""out.txt")我有一个错误((if(qweqwe n)(printtofile n)#f)):
application: not a procedure;
expected a procedure that can be applied to arguments
given: #f
arguments...: [none]
Run Code Online (Sandbox Code Playgroud)
有什么问题?
ADD:我将代码更改为:
(cond
[(equal? n eof) #t]
[else
(if (qweqwe n) (printtofile n) #f)
(next)]
)
Run Code Online (Sandbox Code Playgroud)
但问题仍然存在.
Ósc*_*pez 11
有一些不必要的括号,不要这样做:
((if (qweqwe n) (printtofile n) #f))
Run Code Online (Sandbox Code Playgroud)
试试这个:
(if (qweqwe n) (printtofile n) #f)
Run Code Online (Sandbox Code Playgroud)
也在这里:
(define (qweqwe n)
((cond [(< n 10) #t]
[(>= (lastnum n) (pochtilastnum n)) (qweqwe (quotient n 10))]
[else #f])))
Run Code Online (Sandbox Code Playgroud)
它应该是:
(define (qweqwe n)
(cond [(< n 10) #t]
[(>= (lastnum n) (pochtilastnum n)) (qweqwe (quotient n 10))]
[else #f]))
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,问题是如果你用()表达式包围,这意味着你正在尝试调用一个过程.并且鉴于上述if和cond表达式的结果不返回过程,则会发生错误.此外,begin原始代码中的两个s都是不必要的,a 在每个条件之后cond都有一个隐含的begin,对于过程定义的主体来说是相同的.
| 归档时间: |
|
| 查看次数: |
21267 次 |
| 最近记录: |