1

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?

1
  • @WillNess: You should post that as an answer instead of a comment. Commented Apr 4, 2015 at 22:34

1 Answer 1

1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.