unofficial mirror of emacs-devel@gnu.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).