[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "defmacro" and "local variables" and "let" and "nconc" strange behav
Re: "defmacro" and "local variables" and "let" and "nconc" strange behaviour...
Sun, 13 Jan 2013 19:25:04 +0200
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)
On 2013-01-13, Le Wang wrote:
> On Sun, Jan 13, 2013 at 11:00 PM, Oleksandr Gavenko <address@hidden> wrote:
>> On 2013-01-13, Barry Margolin wrote:
>>> In article <address@hidden>,
>>> Oleksandr Gavenko <address@hidden> wrote:
>>>> I wrote simple macro:
>>>> (defmacro my-filter (pred list)
>>>> "Construct list with elements from LIST which satisfy PRED."
>>>> (let ( (r (make-symbol "r_")) )
>>>> `(let ( (,r '(nil)) )
>>>> (mapc (lambda (item)
>>>> (when (,pred item)
>>>> (nconc ,r (cons item nil))))
>>>> (cdr ,r))))
>>>> Why instead of '(nil) I get something else?
>>> Because nconc is destructively modifying its own source code.
>> I know that nconc destructive. But how this effect '(nil) in defmacro inside
> In lisp, code is data. See my enlightenment process:
I follow you link and found different explanation from Drew Adams:
> Note that different Lisps (and different implementations of the same Lisp) can
> treat a sexp such as '(a b) differently - they might or might not create a new
> list each time it is read or eval'd.
> To be sure to get what you expect in situations like this, do not use '(...).
> Use `cons' or `list' or equivalent backquote syntax. Do not expect '(...) to
> create new list structure each time it is read/eval'd.
That's why my code fail with '(nil)...