Reputation: 117
I'm doing some basic lisp/scheme and I am running into the problem where I can't pass an empty list/null (it is my understanding they behave almost identically) into a function. For example:
(define (fxn L)
(if (null? L)
( '() )
(cdr L)))
And I am getting
> (fxn '())
procedure application: expected procedure, given: () (no arguments)
> (fxn null)
procedure application: expected procedure, given: () (no arguments)
Any advice?
Upvotes: 1
Views: 461
Reputation: 66
This is happening because you have parentheses around '()
in your if statement.
'()
is a literal not a function, therefore you can't call it, i.e, surround it in parentheses.
Try:
(define (fxn L)
(if (null? L)
'()
(cdr L)))
Upvotes: 2