[comp.lang.lisp] Interesting Evaluation?

hall@nvuxh.uucp (25575-Michael R Hall(2498)m000) (03/23/90)

In article <18663@boulder.Colorado.EDU>, schiff@boulder.Colorado.EDU (SCHIFF DAVID) writes:
> I am just learning common lisp and came across a deceptively simple
> looking piece of code, which gave quite a surprising result.  I believe
> I have figured out why but am wondering what an experienced programmer's
> explanation would be.
> 
> (setf a 'global)
> (let ((a 'local)) (eval 'a))
> 
> The result of evaluating the second expression is *of course* "GLOBAL":-)

I think I had this question on a final once.

From Steele's Comm Lisp ed. 1, section 20.1, page 321,
 "eval *form*                                        [Function]
 The *form* is evaluated in the current dynamic environment and a
 NULL LEXICAL ENVIRONMENT."

It goes on to talk about the two levels of evaluation that occur.

What would the following evaluate to?

(defvar a 'global)
(let ((a 'local)) (eval 'a))

Answer ahead

LOCAL, of course.
Michael R. Hall            |"We have seen pictures [of Mars] where there are
hall@nvuxh.cc.bellcore.COM |canals, we believe, and water. If there is water,
rutgers!bellcore!nvuxh!hall|there is oxygen. If oxygen...we can breathe."-Quayle