Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!vsi1!altnet!uunet!steinmetz!duff@eraserhead From: duff@eraserhead (David A Duff) Newsgroups: comp.lang.lisp Subject: Re: Scope of EVAL (was: Re: Summing a list) Summary: Eval does NOT use the lexical environment. Keywords: eval lexical environment Message-ID: <12473@steinmetz.ge.com> Date: 28 Oct 88 20:33:09 GMT References: <10794@srcsip.UUCP> <10813@srcsip.UUCP> <249@pitstop.UUCP> <4154@phoenix.Princeton.EDU> Sender: news@steinmetz.ge.com Reply-To: duff@eraserhead (David A Duff) Organization: GE Corporate Research and Development, Schenectady, NY Lines: 40 In-reply-to: eliot@phoenix.Princeton.EDU (Eliot Handelman) In article <4154@phoenix.Princeton.EDU>, eliot@phoenix (Eliot Handelman) writes: >In article <249@pitstop.UUCP> robv@pitstop.UUCP (Rob Vollum) writes: [... stuff about eval only being able to perform evaluation in the top-level environment.] >Is that really true? In the following example, EVAL consults the lexical >environment, rather that the global. Yes. >(setq x nil) >And now (let* ((x t) (y x)) (eval y)) => t Remember: eval is a function, and the semantics of lisp are such that when evaluating a function application (a list whose car is neither a macro nor a special form), the arguments are evaluated first, then the function is applied. So, basically, whatever you put in place of ... in "(eval ...)" ends up getting evaluated TWICE -- once before eval is called and once after. In your example above, the eval function never sees the symbol y, but is instead passed the value t. To better illustrate the difference between evaluation within a lexical environment and evaluation in the top-level environment (the kind that the lisp eval function does) you probably meant to try something like this: (setq x nil) ;; here x is eval'd in lexical environment: (let ((x t)) x) ==> t ;; here x is eval'd in top-level environment: (let ((x t)) (eval 'x)) ==> nil Dave Duff GE Research and Development Center duff@eraserhead.steinmetz.ge.com Schenectady, New York uunet!steinmetz!eraserhead!duff 518-387-5649 Dave Duff GE Research and Development Center duff@eraserhead.steinmetz.ge.com Schenectady, New York uunet!steinmetz!eraserhead!duff 518-387-5649