Reputation: 387
I can't use at all lambda function, because I get this error: Argument to apply/funcall is not a function: (LAMBDA (E) (COUNT_ATOMS M E)).
And the code is:
> (DEFUN count_atoms (m l)
> (COND ((ATOM l) (COND ((EQUAL m l) 1)
> (t 0)))
> (t (APPLY '+
> (MAPCAR '(LAMBDA (e) (count_atoms m e))
> l)))))
For
(count_atoms 3 '( (3 3) 3 (4 4) 5))
it should print 3.
What is wrong here?
Upvotes: 1
Views: 376
Reputation: 71119
use (MAPCAR #'(LAMBDA (e) (count_atoms m e)) ...
, with the "sharp" sign. Same with apply
, use #'+
.
writing #'(lambda .... )
is the same as writing (function (lambda .... ))
. There's also a macro lambda
which lets you get away with writing just (lambda ... )
there.
see also:
Upvotes: 1