- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is a problem from a Common Lisp book that I am going through, but it should apply to Autolisp as well. The book provides the answer, but I wish it went through exactly why the answer is what it is. It does state It will help to write down what value each variable is bound to and, of course, mind the quotes!
Here is the the definition of the function:
(defun stooge (larry moe curly)
(list larry (list ’moe curly) curly ’larry))
Then the problem asks What does the following evaluate to?
(stooge ’moe ’curly ’larry)
The result is (MOE (MOE LARRY) LARRY LARRY) but I'm having trouble following the logic 100%. I know that the list function creates a new cons cell chain, and you usually work from inside out if there are parenthesis. A symbol has to be quoted & a variable does not, so in the inside parenthesis moe is quoted, but curly is not, which makes me think that moe is the symbol which doesnt get evaluated because it is quoted, but it is the global symbol moe, and curly is a local variable that evaluates to the value that is assigned to it. Somehow larry gets assigned to curly in the list function in the inside parenthesis. The book does state that it is a real head scratcher so hopefully I'm not the only person who has struggled with this problem.
If someone could walk me through the logic of this problem so I could understand it I would appreciate it. I know that a symbol evaluates to the value of the variable it refers to, but I'm having some trouble wrapping my head around this.
Solved! Go to Solution.