all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#62117: 29.0.60; cl-letf on a map place has side-effects
@ 2023-03-11  7:44 Augusto Stoffel
  2023-03-12  0:00 ` Michael Heerdegen
  0 siblings, 1 reply; 4+ messages in thread
From: Augusto Stoffel @ 2023-03-11  7:44 UTC (permalink / raw)
  To: 62117

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.





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

end of thread, other threads:[~2023-03-15  2:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-11  7:44 bug#62117: 29.0.60; cl-letf on a map place has side-effects Augusto Stoffel
2023-03-12  0:00 ` Michael Heerdegen
2023-03-12  6:09   ` Augusto Stoffel
2023-03-15  2:13     ` Michael Heerdegen

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.