[Top][All Lists]

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

Re: Error: add-to-list cannot use lexical var ...

From: Stefan Monnier
Subject: Re: Error: add-to-list cannot use lexical var ...
Date: Tue, 14 Aug 2012 08:48:03 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

>     (let (l)
>       (add-to-list 'l "testing"))

Functions like add-to-list and `set' rely on an equivalence between
symbol objects and variables which is incompatible with lexical scoping.

> You will see an error like.
>     vc-dir.el:54:1:Warning: Unused lexical variable `l'
>     vc-dir.el:54:7:Error: add-to-list cannot use lexical var `l'

> I should say the results are not along the expected lines.  Can someone
> explain it to me?

When interpreted, add-to-list could be made to work by looking up the
lexical environment, searching for the binding of `l'.
But when byte-compiled there's no such option because the byte-code
doesn't even remember that the local var was named `l'.

You can use CL's pushnew (with :test 'equal) instead.


reply via email to

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