From: Tomas Hlavaty <tom@logand.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>, help-gnu-emacs@gnu.org
Subject: Re: Question about let binding behavior
Date: Thu, 10 Oct 2024 09:58:31 +0200 [thread overview]
Message-ID: <87zfncie3c.fsf@neko.mail-host-address-is-not-set> (raw)
In-Reply-To: <jwvr08oluee.fsf-monnier+emacs@gnu.org>
On Wed 09 Oct 2024 at 19:39, Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>> or you can avoid the constant in the first place, for example with
>> minimal change like this:
>>
>> (let ((baz `((quux . 0) (quuz . 0))))
>
> Hmm... I think this makes no difference: ` does not guarantee it returns
> a different object each time.
> And indeed, if you try:
>
> (macroexpand '`((quux . 0) (quuz . 0)))
> =>
> '((quux . 0) (quuz . 0))
ok, try (let ((baz `((quux . ,0) (quuz . ,0))))
(macroexpand '`((quux . ,0) (quuz . ,0)))
=>
(list (cons 'quux 0) (cons 'quuz 0))
although sbcl does not get tricked and requires
CL-USER> (macroexpand '`((quux . ,a) (quuz . ,b)))
(LIST (LIST* 'QUUX A) (LIST* 'QUUZ B))
T
(defun foo2 (bar &optional (a 0) (b 0))
(let ((baz `((quux . ,a) (quuz . ,b))))
(if (> 10 bar)
(setf (cdr (assoc 'quux baz)) bar)
(setf (cdr (assoc 'quuz baz)) bar))
baz))
(foo2 1)
(foo2 100)
in emacs-lisp:
(defun foo2 (bar &optional a b)
(let ((baz `((quux . ,(or a 0)) (quuz . ,(or b 0)))))
(if (> 10 bar)
(setcdr (assoc 'quux baz) bar)
(setcdr (assoc 'quuz baz) bar))
baz))
(foo2 1)
(foo2 100)
although this also works in emacs-lisp (for now?):
(defun foo3 (bar)
(let* ((a 0)
(b 0)
(baz `((quux . ,a) (quuz . ,b))))
(if (> 10 bar)
(setcdr (assoc 'quux baz) bar)
(setcdr (assoc 'quuz baz) bar))
baz))
(foo3 1)
(foo3 100)
next prev parent reply other threads:[~2024-10-10 7:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 6:21 Question about let binding behavior Louis-Guillaume Gagnon
2024-10-08 6:41 ` tomas
2024-10-08 7:49 ` Louis-Guillaume Gagnon
2024-10-08 8:05 ` tomas
2024-10-08 16:02 ` tomas
2024-10-09 8:01 ` Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor
2024-10-09 8:13 ` Tomas Hlavaty
2024-10-09 23:39 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-10 7:58 ` Tomas Hlavaty [this message]
2024-10-10 18:38 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-18 11:25 ` Rudolf Schlatte
2024-10-08 8:15 ` Joost Kremers
2024-10-08 22:27 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-10-08 22:21 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-10-08 15:47 ` [External] : " Drew Adams
2024-10-09 2:28 ` Stefan Monnier via Users list for the GNU Emacs text editor
-- strict thread matches above, loose matches on Subject: below --
2024-10-09 8:34 Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor
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=87zfncie3c.fsf@neko.mail-host-address-is-not-set \
--to=tom@logand.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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.
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).