help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: never use `eval'


From: Pascal J. Bourguignon
Subject: Re: never use `eval'
Date: Fri, 17 Jul 2015 10:55:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <87d1zrlfz6.fsf@kuiper.lan.informatimago.com>,
>  "Pascal J. Bourguignon" <pjb@informatimago.com> wrote:
>> Doesn't seem to work:
>> 
>>     (setf lexical-binding t)
>> 
>>     (let ((x 42))
>>       (eval 'x t))
>>     Debugger entered--Lisp error: (void-variable x)
>> 
>>     (let ((x 42))
>>       (eval 'x nil))
>>     Debugger entered--Lisp error: (void-variable x)
>
> I don't think that could be expected to work. Since eval is a function, 
> not a special form, there's no way it can access the lexical environment 
> outside it. I assume the LEXICAL parameter means that it implements 
> lexical binding in the code being evaluated, e.g. if you do:
>
> (eval '(let ((x 42)) x) t)
>
> it binds x lexically, not dynamically.
>
> But it also says that LEXICAL can be an alist, so you could do:
>
> (eval 'x '((x . 42)))
>
> and it should return 42.

Oh!  I see…  

This is nice, to be able to pass an environment like this, because we
could write macros that would build a "lexical environment" to be passed
to eval…


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]