[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: |
Tue, 04 Jun 2013 22:41:59 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
>> > (let ((x '(a))) (add-to-list 'x 'b) x) -> (b a)
>> Yup, this is asking for trouble. Use `push' or `cl-pushnew' instead.
> Unless you're knee-deep in the internals of the language, the difference
> between `cl-pushnew' and `add-to-list' is so obscure as to be
> incomprehensible.
Agreed. I never liked add-to-list, and now I really know why.
To give you an idea of why `add-to-list' is a problem:
(add-to-list 'o 'b)
does the same as
(add-to-list (intern (substring "ouch" 0 1)) 'b)
so other than by ad-hoc handling the case where the first arg is passed
via quoting, the byte-compiler would have to handle both cases, and the
second case is pretty hopeless.
Stefan
- Is add-to-list supposed to work when lexical-binding is t?, Kelly Dean, 2013/06/03
- Re: Is add-to-list supposed to work when lexical-binding is t?, Kelly Dean, 2013/06/05
- Re: Is add-to-list supposed to work when lexical-binding is t?, Kelly Dean, 2013/06/09
- Re: Is add-to-list supposed to work when lexical-binding is t?, Barry Margolin, 2013/06/10
- Re: Is add-to-list supposed to work when lexical-binding is t?, Kelly Dean, 2013/06/11
- Re: Is add-to-list supposed to work when lexical-binding is t?, Stefan Monnier, 2013/06/13