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

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

Re: never use `eval'


From: Barry Margolin
Subject: Re: never use `eval'
Date: Fri, 17 Jul 2015 04:36:06 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <87d1zrlfz6.fsf@kuiper.lan.informatimago.com>,
 "Pascal J. Bourguignon" <pjb@informatimago.com> wrote:

> Emanuel Berg <embe8573@student.uu.se> writes:
> 
> > Remember when I said the byte compiler should be more
> > offensive and offer more elaborate style warnings?
> >
> > And this is a good example of that!
> >
> > Even in the Emacs help
> >
> >     (describe-function 'eval)
> >
> > it doesn't say anything about the dangers of the
> > "nil environment":
> >
> 
>    (eval FORM &optional LEXICAL)
> 
> >     Evaluate FORM and return its value.
> >     If LEXICAL is t, evaluate using lexical scoping.
> >     LEXICAL can also be an actual lexical environment,
> >     in the form of an alist mapping symbols to
> >     their value.
> 
> 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.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

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