问题
I'm trying to return (values str ((+ x 3) y)) from the function it resides in.
code snippet:
(if (<my condition>)
(values str ((+ x 3) y))
(values str ((+ x 2) y)))
gives error:
(+ X 3) SHOULD BE A LAMBDA EXPRESSION
but (values str (y (+ x 3)))
works fine.
why?
回答1:
The S-expression ((+ x 3) y)
cannot be evaluated because the first list element is not funcallable (it should name a function or be a lambda expression).
So, to avoid evaluation, you need to quote it:
(if (<my condition>)
(values str '((+ x 3) y))
(values str '((+ x 2) y)))
Then you will return a list of length 2 (containing a list of length 3 and a symbol y
) as your second value. If, however, you want to return the values of (+ x 2)
and y
in the list, you will want to do something like
(values str (list (+ x (if <condition> 3 2)) y))
or maybe return 3 values instead of 2:
(values str
(+ x (if <condition> 3 2))
y)
On the other hand, y
is a symbol, which, apparently, names a function in your image, so (y (+ x 3))
evaluates fine (it calls function y
on the result of adding 3
to x
).
来源:https://stackoverflow.com/questions/22163216/lisp-should-be-a-lambda-expression