From: Harald Hanche-Olsen <hanche@math.ntnu.no>
To: emacs-devel@gnu.org
Subject: Re: Why are there two dolist?
Date: Tue, 11 Aug 2009 21:24:23 -0400 (EDT) [thread overview]
Message-ID: <20090811.212423.254477990.hanche@math.ntnu.no> (raw)
In-Reply-To: <e01d8a50908111733t2cdb1ecajd73bd5eed828d8ee@mail.gmail.com>
+ Lennart Borgman <lennart.borgman@gmail.com>:
> I do not understand your code above, but is not the conclusion that
> the cl-macs.el version does not do what it is supposed to do?
Yeah, at least as far as the lexically-scoped claim goes.
> What value does it have then?
At least in simpler usage, it does provide a block that return-from
can use for a non-local exit, so it has some value.
Actually, the bug seems to be in block, not in dolist. My example was
perhaps overly complex. Here is a simpler example, using only two
nested blocks, both named b:
(block b
(flet ((f (x) (return-from b x)))
(list 'inner-block-returned (block b (f 42)))))
In common lisp, the innermost call (f 42) executes a return-from that
is lexically inside the outer block but not inside the inner one, so
the value 42 is returned from the outer block. In elisp, on the other
hand, the return-from inside foo causes the inner block to return 42,
so the flet, and hence the outer block, returns instead the list
(inner-block-returned 42).
This seems to me to flatly contradict what is said about lexical
scoping in the docstring of block.
Oh, but wait: Looking at the code for block, I begin to suspect that
byte compilation might make a difference. And indeed it does:
(defun foo ()
(block b
(flet ((f (x) (return-from b x)))
(list 'inner-block-returned (block b (f 'bar))))))
(foo) ; => (inner-block-returned bar)
(byte-compile 'foo)
(foo) ; => bar
So byte-compiling a block produces the expected result.
Oh well, I guess this is just one more wart on the cl package. (It has
a few, but I find it useful anyhow.) I still think that inadvertently
using the cl version of dolist cannot possibly harm any elisp code
that does not otherwise rely on cl.
- Harald
prev parent reply other threads:[~2009-08-12 1:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-11 22:14 Why are there two dolist? Lennart Borgman
2009-08-11 22:36 ` Lennart Borgman
2009-08-12 8:45 ` David Kastrup
2009-08-12 8:52 ` Lennart Borgman
2009-08-11 22:37 ` Miles Bader
2009-08-11 22:42 ` Lennart Borgman
2009-08-11 22:51 ` Miles Bader
2009-08-11 23:04 ` Lennart Borgman
2009-08-11 23:30 ` Harald Hanche-Olsen
2009-08-11 23:34 ` Miles Bader
2009-08-11 23:41 ` Lennart Borgman
2009-08-11 23:48 ` Miles Bader
2009-08-11 23:39 ` Lennart Borgman
2009-08-12 0:27 ` Harald Hanche-Olsen
2009-08-12 0:33 ` Lennart Borgman
2009-08-12 0:54 ` Miles Bader
2009-08-12 0:59 ` Lennart Borgman
2009-08-12 1:24 ` Harald Hanche-Olsen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090811.212423.254477990.hanche@math.ntnu.no \
--to=hanche@math.ntnu.no \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).