all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams
Date: Wed, 14 Sep 2016 23:47:47 -0400	[thread overview]
Message-ID: <63ebf6ee-d623-e863-42a8-bc802d3df54d@gmail.com> (raw)
In-Reply-To: <87zina568j.fsf@web.de>


[-- Attachment #1.1: Type: text/plain, Size: 3862 bytes --]

On 2016-09-14 20:58, Michael Heerdegen wrote:
> Clément Pit--Claudel <clement.pit@gmail.com> writes:
> 
>> Ok, so we agree on this part :) Note that it may be nonsense to load
>> the file into a buffer, too; holding the full file in a list is more
>> or less as bad as holding the full file in a buffer.  If the file is
>> large, that's very inefficient.
> 
> Ok.  But how do you refer to the file's contents from elisp, then?
> As a string?

I didn't have a string in mind.  More something like running `cat` in a subprocess maybe?

>>> Do you have an example where this would be useful for streams in
>>> Emacs, different from the "last n lines" one (see my comment about
>>> that below).
>>
>> Sure: if I have a stream of numbers, I may want to calculate the
>> average of the last n numbers.
> 
>> Or if I have a stream of non-overlapping buffer spans, I may want to
>> remove just the last one.
> 
> Sure, but with what I mean, the error (inefficiency) would already be in
> the "I have..." part.

I don't think so :) These sound like reasonable streams to me ^^
The second one in particular is one that I used recently: I wanted to enumerate all spans with constant text properties, and I didn't need to keep the whole list of spans in memory.  On the other hand, I didn't want to put the buffer segmentation in each function that iterated over the spans. Using a stream for that was quite convenient.

>> To continue on the `last n lines' example, I may be interested in only
>> the last n lines of output of a running process (think dmesg | tail).
> 
> As a string, right?  Or in which way do you refer to the process output
> via streams?  Can you please explain in short how you are using streams
> in your use case?  (Sorry, I'm more a mathematician than a programmer,
> so it's not your fault if I miss the point).

I don't have a concrete use case :) This thread was born just from my looking at the original patch.  I use streams a lot more in other languages than I do in Emacs Lisp, at least for now.  And I agree that there's no hurry in implementing this feature, either (we could add it later).

> And should we add `stream'
> method implementations for building streams from files and/or processes
> to stream.el if such stuff is useful?

I think this would be great.  The comment at the top of stream.el mentions it:

;; streams could be created from any sequential input data:
;; - sequences, making operation on them lazy
;; - a set of 2 forms (first and rest), making it easy to represent infinite sequences
;; - buffers (by character)
;; - buffers (by line)
;; - buffers (by page)
;; - IO streams
;; - orgmode table cells
;; - ...

> But I guess I'm beginning to understand: if you have a string (or
> something "similar") consisting of multiple lines (or records or
> whatever), and you are interested in the last n lines, in contrast to a
> buffer, the "go to the end and then n times backwards" approach might
> not even be possible, so there is no alternative to dissect the complete
> string into entities from the start until you hit the end (and throw
> away most of the stuff without accumulation) -- i.e. to the sliding
> window approach implemented by seq-subseq with negative indexes.

Yes, essentially.  In the string case, though, you could copy the string into a buffer and apply the trick that you mentioned.  But more generally streams are good at producing their contents lazily, so an implementation that requires forcing the entire stream and then searching from the end of the resulting list is non-optimal. Of course in some cases you can just skip the production of a stream entirely; but not in all cases.

In any case, I don't think this should hold the previous patch; we can always extend the functionality of seq-subseq later.

Clément.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-09-15  3:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13 16:23 [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams Michael Heerdegen
2016-09-13 18:02 ` Clément Pit--Claudel
2016-09-13 21:17   ` Michael Heerdegen
2016-09-14  1:24     ` Clément Pit--Claudel
2016-09-14 15:05       ` Michael Heerdegen
2016-09-14 23:26         ` Clément Pit--Claudel
2016-09-15  0:51           ` John Mastro
2016-09-15  2:00             ` Clément Pit--Claudel
2016-09-15 17:01               ` John Mastro
2016-09-15 21:07               ` Michael Heerdegen
2016-09-15 22:18                 ` Clément Pit--Claudel
2016-09-15 22:28                   ` Michael Heerdegen
2016-09-15 22:52                     ` Clément Pit--Claudel
2016-09-15  0:58           ` Michael Heerdegen
2016-09-15  3:47             ` Clément Pit--Claudel [this message]
2016-09-15  8:42               ` Nicolas Petton
2016-09-15 22:30                 ` Michael Heerdegen
2016-09-15 23:08                   ` Nicolas Petton
2016-09-15 21:29               ` Michael Heerdegen
2016-09-14  1:28     ` John Wiegley
2016-09-14 15:15       ` Michael Heerdegen
2016-09-13 22:20 ` Nicolas Petton
2016-09-13 22:40   ` Michael Heerdegen
2016-09-14  8:25     ` Nicolas Petton

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=63ebf6ee-d623-e863-42a8-bc802d3df54d@gmail.com \
    --to=clement.pit@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    /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.