unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Augusto Stoffel <arstoffel@gmail.com>
To: 62117@debbugs.gnu.org
Subject: bug#62117: 29.0.60; cl-letf on a map place has side-effects
Date: Sat, 11 Mar 2023 08:44:26 +0100	[thread overview]
Message-ID: <875yb7vijp.fsf@gmail.com> (raw)

Consider this example:

--8<---------------cut here---------------start------------->8---
(require 'cl-lib)
(defun f (map)
  (cl-letf (((map-elt map 'a) 1))
     map))

(let ((map '(b 2)))
  (f map)
  map)
=> (b 2 a nil)

(let ((map (make-hash-table)))
  (f map)
  (map-length map))
=> 1
--8<---------------cut here---------------end--------------->8---

I would expect `f' to have no side effects, so get (b 2) and 0
respectively in the two examples.

For comparison, plist-get as a place has no side-effect:

--8<---------------cut here---------------start------------->8---
(defun g (map)
  (cl-letf (((plist-get map 'a) 1))
    map))

(let ((map '(b 2)))
  (g map)
  map)
(b 2)
--8<---------------cut here---------------end--------------->8---

Of course it's usual to treat a nil entry and no entry as equivalent in
Lisp, but this behavior can be a problem e.g. when constructing data to
pass to other programs.





             reply	other threads:[~2023-03-11  7:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-11  7:44 Augusto Stoffel [this message]
2023-03-12  0:00 ` bug#62117: 29.0.60; cl-letf on a map place has side-effects Michael Heerdegen
2023-03-12  6:09   ` Augusto Stoffel
2023-03-15  2:13     ` Michael Heerdegen

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=875yb7vijp.fsf@gmail.com \
    --to=arstoffel@gmail.com \
    --cc=62117@debbugs.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).