[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
"defmacro" and "local variables" and "let" and "nconc" strange behaviour
From: |
Oleksandr Gavenko |
Subject: |
"defmacro" and "local variables" and "let" and "nconc" strange behaviour... |
Date: |
Sun, 13 Jan 2013 16:15:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
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))))
When I evaluate several times:
(my-filter (lambda (x) x) '(1 nil "a"))
I get sequentially:
(1 "a")
(1 "a" 1 "a")
(1 "a" 1 "a" 1 "a")
(1 "a" 1 "a" 1 "a" 1 "a")
When I eval:
(pp (macroexpand '(my-filter (lambda (x) x) '(1 nil "a"))))
I get:
(let
((r_
'(nil 1 "a" 1 "a" 1 "a" 1 "a" 1 "a" 1 "a" 1 "a" 1 "a")))
(mapc
(lambda
(item)
(when
((lambda
(x)
x)
item)
(nconc r_
(cons item nil))))
'(1 nil "a"))
(cdr r_))
Why instead of '(nil) I get something else?
--
Best regards!
- "defmacro" and "local variables" and "let" and "nconc" strange behaviour...,
Oleksandr Gavenko <=