all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#27177: 26.0.50: Macroexpanding cl-loop and friends (make-symbol usage)
@ 2017-05-31 23:23 Alex
  2017-05-31 23:51 ` Michael Heerdegen
  0 siblings, 1 reply; 17+ messages in thread
From: Alex @ 2017-05-31 23:23 UTC (permalink / raw)
  To: 27177

Consider the following simple cl-loop form:

(cl-loop for x in '(1 2 3)
         for y in '(a b c)
         collect (list x y))


The macroexpanded result is:

(cl-block nil
  (let*
      ((--cl-var--
        '(1 2 3))
       (x nil)
       (--cl-var--
        '(a b c))
       (y nil)
       (--cl-var-- nil))
    (while
        (and
         (consp --cl-var--)
         (progn
           (setq x
                 (car --cl-var--))
           (consp --cl-var--)))
      (setq y
            (car --cl-var--))
      (push
       (list x y)
       --cl-var--)
      (setq --cl-var--
            (cdr --cl-var--))
      (setq --cl-var--
            (cdr --cl-var--)))
    (nreverse --cl-var--)))


It's easy to verify that this expansion doesn't do the same job by
noticing that the macroexpanded form always returns nil.

Note that in Common Lisp (at least in SBCL), macroexpanding and then
evaluating the result works as expected.

This is because cl-macs.el uses make-symbol instead of gensym, like SBCL
does.

Should cl-loop and friends use cl-gensym? One possible disadvantage to
that approach is that since Emacs Lisp lacks CL's bignums, it could lead
to some issues past most-positive-fixnum.

The reason I reported this is actually because I found it difficult to
debug macroexpanded cl-loop forms when all of the uninterned symbols had
the same representation. Using cl-gensym would help with debugging.





^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-08-24 14:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-31 23:23 bug#27177: 26.0.50: Macroexpanding cl-loop and friends (make-symbol usage) Alex
2017-05-31 23:51 ` Michael Heerdegen
2017-06-01  0:29   ` Alex
2017-06-01  0:52     ` npostavs
2017-06-01  1:01     ` Michael Heerdegen
2017-06-01  2:02       ` Alex
2017-06-02  3:27         ` Michael Heerdegen
2017-06-02  4:42           ` Alex
2017-06-02 23:09             ` Michael Heerdegen
2017-06-02 23:17             ` npostavs
2017-06-02 23:46               ` Alex
2017-06-03  2:33             ` Stefan Monnier
2017-06-04  0:24               ` Alex
2017-06-06  4:20                 ` Stefan Monnier
2017-06-06 20:31                   ` Alex
2020-08-24 14:53               ` Lars Ingebrigtsen
2017-06-01  0:29   ` npostavs

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.