From: Michael Heerdegen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: Okamsn <okamsn@protonmail.com>,
Nicolas Petton <nicolas@petton.fr>,
Stefan Monnier <monnier@iro.umontreal.ca>,
73431@debbugs.gnu.org
Subject: bug#73431: Add `setf` support for `stream.el` in ELPA
Date: Sat, 28 Sep 2024 01:55:43 +0200 [thread overview]
Message-ID: <87bk08odmo.fsf@web.de> (raw)
In-Reply-To: <87jzexqgg8.fsf@posteo.net> (Philip Kaludercic's message of "Fri, 27 Sep 2024 15:11:51 +0000")
Hi,
I agree to what Stefan is saying.
Philip Kaludercic <philipk@posteo.net> writes:
> Being able to modify the head of a buffer-stream using setf seems like
> something that could be useful, and certainly more efficient than what
> many people want to do with splitting the return value of
> (buffer-string).
AFAIK, what you normally do in this situation is creating a new stream
reusing the tail of the given one, like in this toy example:
#+begin_src emacs-lisp
(cl-labels ((integers (&optional from)
(let ((from (or from 1)))
(stream-cons from (integers (1+ from))))))
(let ((my-natural-numbers (integers 1))) ;a stream of the natural numbers: 1, 2, ...
(let ((my-natural-numbers-with-head-replaced ;let's "replace" the first element:
(stream-cons 'not-1 (stream-rest my-natural-numbers))))
;; Test: what are the first 10 elements of this second stream?
(seq-into
(seq-subseq my-natural-numbers-with-head-replaced 0 10)
'list))))
#+end_src
Modifying elements later in the stream conflicts a bit with the idea of
a delayed data structure. The above idea can be modified to work in
this case too, though. Creating a new stream even makes more
transparent what is going on... I don't want to tell anybody how to
work with these guys, but that's how I learned it at university.
In typical scenarios the elements before the one to change already have
been processed and been thrown away, and the element you
actually are interested in is the head element most of the time. Like
for a queue.
For buffer contents listing streams I could imagine that one could make
such a thing invalidate itself when the buffer has been modified;
like here [I only added few lines to the
(stream ((buffer buffer) &optional pos)) implementation]:
#+begin_src emacs-lisp
(cl-defmethod my-buffer-chars (buffer &optional pos)
(let ((mods (buffer-modified-tick))) ; added
(with-current-buffer buffer
(unless pos (setq pos (point-min)))
(if (>= pos (point-max))
(stream-empty))
(stream-cons
(with-current-buffer buffer
(save-excursion
(save-restriction
(widen)
(goto-char pos)
(char-after (point)))))
(if (not (eq mods (buffer-modified-tick))) ; added
(error "Buffer has been modified") ; added
(my-buffer-chars buffer (1+ pos)))))))
#+end_src
Already generated elements normally can't "invalidate themselves",
unless you make them functions. But a whole stream that regenerates or
recomputes itself doesn't seem natural to me. You would rather check
whether the stream is still valid _explicitly_ - and if not, just call
the function that returned that stream (most of the time a named
function, like above) again to create a new stream - in the above
example, possibly with an adopted POS argument.
My two cents.
Michael.
prev parent reply other threads:[~2024-09-27 23:55 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 1:33 bug#73431: Add `setf` support for `stream.el` in ELPA Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-24 10:15 ` Philip Kaludercic
2024-09-24 13:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-25 0:17 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-25 2:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-25 20:22 ` Philip Kaludercic
2024-09-26 13:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-27 15:11 ` Philip Kaludercic
2024-09-27 16:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-27 20:08 ` Philip Kaludercic
2024-09-27 20:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-28 3:08 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-28 14:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-29 19:30 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-30 22:19 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-02 1:02 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-02 19:39 ` Philip Kaludercic
2024-10-03 0:19 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-04 8:55 ` Philip Kaludercic
2024-10-05 2:44 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-05 9:14 ` Philip Kaludercic
2024-10-06 1:36 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-19 0:59 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-21 15:48 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-21 20:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-22 13:12 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 2:51 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-27 10:06 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-08 1:45 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-18 2:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-27 14:26 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-28 9:42 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 1:15 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 2:00 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 9:57 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 10:35 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 12:43 ` Eli Zaretskii
2024-10-29 13:31 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 15:43 ` Eli Zaretskii
2024-10-29 16:09 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 17:06 ` Eli Zaretskii
2024-10-29 17:29 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 17:50 ` Eli Zaretskii
2024-10-29 15:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 15:05 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 16:19 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 16:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-19 10:41 ` Philip Kaludercic
2024-10-05 13:32 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-06 0:37 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-27 23:55 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors [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=87bk08odmo.fsf@web.de \
--to=bug-gnu-emacs@gnu.org \
--cc=73431@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
--cc=nicolas@petton.fr \
--cc=okamsn@protonmail.com \
--cc=philipk@posteo.net \
/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).