all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* "defmacro" and "local variables" and "let" and "nconc" strange behaviour...
@ 2013-01-13 14:15 Oleksandr Gavenko
  2013-01-13 14:18 ` Oleksandr Gavenko
       [not found] ` <mailman.17291.1358086805.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Oleksandr Gavenko @ 2013-01-13 14:15 UTC (permalink / raw)
  To: help-gnu-emacs

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!




^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <mailman.17290.1358086558.855.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2013-01-14  9:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-13 14:15 "defmacro" and "local variables" and "let" and "nconc" strange behaviour Oleksandr Gavenko
2013-01-13 14:18 ` Oleksandr Gavenko
     [not found] ` <mailman.17291.1358086805.855.help-gnu-emacs@gnu.org>
2013-01-14  9:04   ` jack-mac
     [not found] <mailman.17290.1358086558.855.help-gnu-emacs@gnu.org>
2013-01-13 14:21 ` Barry Margolin
2013-01-13 15:00   ` Oleksandr Gavenko
2013-01-13 16:45     ` Le Wang
2013-01-13 17:25       ` Oleksandr Gavenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.