emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams


From: Michael Heerdegen
Subject: Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams
Date: Thu, 15 Sep 2016 23:29:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Clément Pit--Claudel <address@hidden> writes:

> 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?

I have a question: AFAIK there is no mean to delay Emacs from accepting
output from a process (or is there? sorry if i missed it then).  But
when we must collect the complete process output when it arrives...and
we don't have asynchronity in Emacs etc...of what use is the usage of a
delayed structure (stream) in this case at all, and how would it be
different from the string case?

>> Sure, but with what I mean, the error (inefficiency) would already
>> be inthe "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.

Here I again would chime in: it's convenient, but not efficient.  Search
backwards from the end of the buffer, don't enumerate from the beginning
if you are only interested in the last n, and start building a stream if
you have found the right place to start.

> > 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.

Maybe you want to give it a try?  Then we will at least know how useful
that would be ;-)

> > 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.

Well, I learned some time ago that because a buffer is more complicated
than a string, most operations are slower for a buffer than for an
equivalent string.

> 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.

Yes, but that's was not my argument: I wanted to avoid this stream
entirely in such cases.  For your use case (of the negative indexes),
forcing the entire stream is unavoidable.  That's the point I criticize.

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

Ok, so I think I'll just install the patch for now.


Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]