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

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

Re: Is add-to-list supposed to work when lexical-binding is t?


From: Stefan Monnier
Subject: Re: Is add-to-list supposed to work when lexical-binding is t?
Date: Mon, 03 Jun 2013 21:49:58 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> Section 11.9.3 (Lexical Binding) in the manual says "functions like
> `symbol-value', `boundp', and `set' only retrieve or modify
> a variable's dynamic binding".  Why?

Because a variable is not the same thing as a symbol.

For dynamic binding, you can somewhat blur the difference and use the
symbol's value cell as "the content of the variable of that name"
because let-binding just temporarily changes the only global value.

With lexical scoping, a given variable name can have many different
values at the same time so this is not an option.

> (let ((x '(a))) (add-to-list 'x 'b) x) -> (b a)

Yup, this is asking for trouble.  Use `push' or `cl-pushnew' instead.


        Stefan




reply via email to

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