all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* cl-block less lexical than expected
@ 2021-12-30 18:12 Robin Tarsiger
  2021-12-30 18:15 ` Robin Tarsiger
  2021-12-30 18:50 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Robin Tarsiger @ 2021-12-30 18:12 UTC (permalink / raw)
  To: Emacs-Devel List

Greetings.

Today I was poking around with elisp and decided to look at the
definitions of cl-block and cl-return-from. These are predictably
described in the elisp manual as using lexical tags along the lines
of how actual-CL block and return-from work. However, the way the
macros are implemented doesn't line up with this; they do a static
transformation on the tag name and then intern the result for use
with catch/throw, and that yields dynamic semantics:

   (defun tmp/cl-block-test-1 ()
     (cl-block foo
       (cl-return-from foo 'ok)
       'not-reached))

   (defun tmp/cl-block-test-2 ()
     (cl-return-from foo 'bad))

   (defun tmp/cl-block-test-3 ()
     (cl-block foo
       (tmp/cl-block-test-2)
       ;; Necessary to avoid the catch being discarded.
       (cl-return-from foo 'correct)))

   (tmp/cl-block-test-1)
   ==> ok ; This is fine.

   (tmp/cl-block-test-2)
   ==> <signals error> ; Also okay.

   (tmp/cl-block-test-3)
   ==> bad ; But the foo block isn't actually lexical!

I have to think that since catch and throw both take evaluated
expressions for their tags, a more suitable implementation might
do a static transformation to choose an out-of-the-way lexical
_variable_ name which would then be let-bound to a gensym during
the body. cl-return-from could then try to evaluate the variable
to get the tag; the warnings/errors for bad tags would be awkward
to read, but at least the semantics would be correct. An unbound
tag variable would also be warned about during byte-compilation.

Thoughts?

-RTT



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

end of thread, other threads:[~2022-01-04 20:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-30 18:12 cl-block less lexical than expected Robin Tarsiger
2021-12-30 18:15 ` Robin Tarsiger
2021-12-30 18:50 ` Stefan Monnier
2022-01-04 19:29   ` Robin Tarsiger
2022-01-04 20:11     ` Eli Zaretskii

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.