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: Wed, 14 Sep 2016 17:05:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

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

> I don't think converting to list would be a good idea.  When operating
> on text files, for example, it's often convenient to get the last n
> lines of a file.  If the file is represented as a stream of lines,
> then tail makes sense.  Doesn't it?  Converting the file to a list of
> lines beforehand sounds like a bad idea, memory wise.

Indeed, in this case, it would be nonsense to convert into a list.

> I don't see why; isn't it common to implement slyding-window-style
> algorithms on data streams? 'tail' is just one such example.

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

> Let me know what you think of the 'last n lines of a file' example.

I think this is actually a very good example why it is good to forbid
negative indexes.  If you are interested in the last n lines of a file,
why would you dissect the complete file (or buffer) into lines and throw
away nearly all of the result?  In Emacs, if you dissect a buffer into
its lines, this can take seconds if the buffer is a bit larger (no
matter if you collect the lines in a data structure or just throw the
result away).  If you are interested in the last n lines, this is
potentially unlimited inefficient.

Instead, go to the end of buffer, go back N lines, and start building a
stream from there.

So, in this case, in my opinion forbidding negative indexes would have
saved you from the error of writing bad code.  Negative indexes would be
an invitation to write bad code.

Maybe it would be better to provide that semantics in a separate
function, so that the programmer is forced to think about what he is
doing.  WDYT?


Regards,

Michael.



reply via email to

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