[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "defmacro" and "local variables" and "let" and "nconc" strange behav
From: |
Oleksandr Gavenko |
Subject: |
Re: "defmacro" and "local variables" and "let" and "nconc" strange behaviour... |
Date: |
Sun, 13 Jan 2013 19:25:04 +0200 |
User-agent: |
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 <gavenkoa@gmail.com>
> wrote:
>> On 2013-01-13, Barry Margolin wrote:
>>
>>> In article <mailman.17290.1358086558.855.help-gnu-emacs@gnu.org>,
>>> Oleksandr Gavenko <gavenkoa@gmail.com> 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))))
>>>> ,list)
>>>> (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:
> http://comments.gmane.org/gmane.emacs.bugs/50783
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)...
--
Best regards!