Why doesn't set work with lambda in Common Lisp?

77 Views Asked by At

I am writing a lisp interpreter (in C), and am at the point of implementing lambda functions and the set language features. In my interpreter the following works:

(set 'f (lambda (x) (cdr x)))
(f '(a b c))

outputting (b c). However, apparently this kind of thing is not allowed in Common Lisp as I get Input a value to be used instead of (FDEFINITION 'F) when I try this in clisp. My questions are the following:

  1. Why is this not allowed in Common Lisp?
  2. How does one achieve the same thing in Common Lisp?
  3. What should be changed in my interpreter so that this kind of thing is not allowed?

To help in your answering of the last question– currently the set primitive basically just associates an atom with a value in the environment. The above code works in my interpreter because to evaluate (f '(a b c)) it looks up f in the environment, finds that it is a lambda function, and then applies that lambda function to the argument '(a b c).

Thanks for the help.

Edit: This is not a duplicate of "What is the difference between Lisp-1 and Lisp-2?". Although differences between Lisp-1 and Lisp-2 may be the source of why this doesn't work in clisp, my question really centers on the mechanisms of the set primitive and it's underlying implementation.

0

There are 0 best solutions below