Path: utzoo!utgpu!water!watmath!clyde!ima!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: LISP PROBLEM Message-ID: <24909@think.UUCP> Date: 4 Aug 88 04:05:53 GMT References: <5071@zodiac.UUCP> Sender: usenet@think.UUCP Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 31 In article <5071@zodiac.UUCP> yushen@ads.com (Yu-shen Ng) writes: >How can I do an "eval" within the lexical scope from which the "eval" is called? You can't. EVAL is an ordinary function, so it has no idea what lexical context it was called in (only special forms and macros can access the lexical context). How would it possibly work in a compiled function, when references to lexical variables have been converted to stack frame offsets, and the names of the local variables have been discarded? If the Lisp implementation saves the local variable information (as it does on Lisp Machines) then there will likely be an implementation-specific function for evaluating in a given lexical environment (for use by the debugger, for instance); a common mechanism is to allow EVAL to take an optional second argument, which is the lexical environment. However, Common Lisp doesn't require this capability. Why do you need this capability? If the form you want to evaluate is coming from outside the function, how could it possibly know the names of your local variables? Perhaps you should describe what you are trying to accomplish, since I suspect you may be going about it wrong. It is almost always wrong to call EVAL explicitly from a function. You can usually do what you want with FUNCALL or APPLY. Barry Margolin Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar