以下是代码(also here):
#lang racket
(define poorY
((lambda length
(lambda (ls)
(cond
[(null? ls) 0]
[else (add1 ((length length) (cdr ls)))])))
(lambda length
(lambda (ls)
(cond
[(null? ls) 0]
[else (add1 ((length length) (cdr ls)))])))))
当我运行它时:
> (poorY '(9 7 8))
. . application: not a procedure;
expected a procedure that can be applied to arguments
given: '(#<procedure>)
arguments...:
'(#<procedure>)
屏幕截图如下所示:
我正在使用DrRacket作为代表。 代码有什么问题?
答案 0 :(得分:9)
length
周围应该有括号:
(define poorY
((lambda (length) ;; here
(lambda (ls)
(cond
[(null? ls) 0]
[else (add1 ((length length) (cdr ls)))])))
(lambda (length) ;; and here
(lambda (ls)
......
您可以尝试
,而不是两次输入相同的长lambda表达式(define poorY
((lambda (f) (f f))
(lambda (length)
(lambda (ls)
(cond
[(null? ls) 0]
[else (add1 ((length length) (cdr ls)))])))))