[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 ***
- never use `eval' (was: Re: How to mapcar or across a list?), (continued)
- Message not available
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Barry Margolin, 2015/07/15
- Message not available
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Barry Margolin, 2015/07/15
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Emanuel Berg, 2015/07/15
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Emanuel Berg, 2015/07/16
- Message not available
- Re: never use `eval', Pascal J. Bourguignon, 2015/07/16
- Re: never use `eval', Emanuel Berg, 2015/07/16
- Re: never use `eval',
Barry Margolin <=
- Re: never use `eval', Pascal J. Bourguignon, 2015/07/17
- Message not available
- Re: never use `eval', Pascal J. Bourguignon, 2015/07/15
- Re: never use `eval', Emanuel Berg, 2015/07/15
Re: How to mapcar or across a list?, Pascal J. Bourguignon, 2015/07/15
Re: How to mapcar or across a list?, Barry Margolin, 2015/07/15