我正在做一些基本的 lisp/scheme,我遇到了无法将空列表/null(据我了解它们的行为几乎相同)传递给函数的问题。 例如:
(define (fxn L)
(if (null? L)
( '() )
(cdr L)))
我得到了
> (fxn '())
procedure application: expected procedure, given: () (no arguments)
> (fxn null)
procedure application: expected procedure, given: () (no arguments)
有什么建议吗?
最佳答案
发生这种情况是因为您在 if 语句中将 '()
括起来了。
'()
是文字而不是函数,因此您不能调用它,即不能将其括在括号中。
尝试:
(define (fxn L)
(if (null? L)
'()
(cdr L)))
关于计划将空列表作为函数参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47523092/