From: okamsn--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>,
Michael Heerdegen <michael_heerdegen@web.de>
Cc: 70524@debbugs.gnu.org
Subject: bug#70524: [PATCH] Fix `map-elt` with `setf` for subplaces
Date: Thu, 25 Apr 2024 01:59:36 +0000 [thread overview]
Message-ID: <9a68b4fc-55ee-41fc-aa2c-c69e9498aff0@protonmail.com> (raw)
In-Reply-To: <jwv4jbqwonj.fsf-monnier+emacs@gnu.org>
Stefan Monnier wrote:
>>> Currently, the use
>>>
>>> (let ((arr (vector 0 1 2 3 4 5 6)))
>>> (setf (map-elt (cl-subseq arr 3) 0)
>>> 27)
>>> arr)
>>>
>>> expands to [...]
>>
>> But... I must admit I'm not really convinced that this has to be
>> changed.
>
> I'm also unconvinced. AFAICT the same problem occurs with
>
> (setf (aref (cl-subseq arr 3) 0) 27)
>
> and I can't think of a good reason why `map-elt` should behave differently.
I would have assumed that `aref` would work with subplaces. I am still
thinking of `setf` like a more flexible version of Python allowing
things like `my_list[0][0] = 27`.
> Furthermore, the change would also fundamentally change the way
> `map-elt` can be used as a gv-place, in the sense that
>
> (setf (map-elt (funcall foo bar) 0) 27)
>
> would signal an error during macroexpansion because (funcall foo bar)
> is not a valid gv-place.
I am trying to come up with an example that triggers the second path
using `map-insert` in the examples that I sent. In the second path, the
current version of the `map-elt` setter will already correctly set the
subplace using `cl-replace`. I am trying to find an example where the
inconsistency makes a difference.
My purpose with this patch and for bug#68863 regarding `seq-subseq`
(which does not currently support `setf`, and I think should allow
subplaces like `substring` claims to) was for destructuring as
`setf`-able places, like in cl-loop's `for VAR in-ref LIST`. I have
implemented that for my Emacs Lisp package
(https://github.com/okamsn/loopy), but not all of the `setf`-able
destructuring constructs support sub-places in the expected way, due to
how some of the GV expansions are defined. I did not consider calling
`setf` on a function's output.
For example, with the two patches, one can do
;; => (1 2 [29 99] 29)
(let ((arr (vector 1 2 88 99)))
(loopy-ref (([a b &rest [&whole c &map (0 map-idx-0)]]
arr))
(setf map-idx-0 29)
(list a b c map-idx-0)))
and have the `setf`-able destructuring work as expected.
>> But second - doesn't your patch lead to very inefficient code in this
>> example, where nearly all elements of the original sequence get replaced
>> by themselves in a loop (through the setter of `cl-subseq')?
>
> Yes, that's another issue. I think if wvale want to support such
`setf` in
> a way that is good enough to that we can recommend its use, we'd need to
> turn it into something that behaves more or less like:
> val
> (map-set! arr (+ 3 0) 27)
>
> But I must admit that I don't know how to get there.
This is true. I could have used `setf (map-elt (cl-subseq arr 3 4) 0)
27)` to be more efficient.
Thank you.
next prev parent reply other threads:[~2024-04-25 1:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 2:10 bug#70524: [PATCH] Fix `map-elt` with `setf` for subplaces Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-24 6:06 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-24 20:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-25 1:59 ` okamsn--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-04-25 12:49 ` Augusto Stoffel
2024-04-26 12:19 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-29 1:08 ` okamsn--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-29 1:54 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-30 16:17 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-25 12:03 ` Augusto Stoffel
2024-04-25 12:42 ` Augusto Stoffel
2024-05-06 14:02 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9a68b4fc-55ee-41fc-aa2c-c69e9498aff0@protonmail.com \
--to=bug-gnu-emacs@gnu.org \
--cc=70524@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
--cc=okamsn@protonmail.com \
/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 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.