unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: "Clément Pit--Claudel" <clement.pit@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams
Date: Wed, 14 Sep 2016 17:05:22 +0200	[thread overview]
Message-ID: <87vaxywmh9.fsf@web.de> (raw)
In-Reply-To: <27962aa1-ae40-99f8-64ad-ae21012fb36e@gmail.com> ("Clément Pit--Claudel"'s message of "Tue, 13 Sep 2016 21:24:34 -0400")

Clément Pit--Claudel <clement.pit@gmail.com> 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	other threads:[~2016-09-14 15:05 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 [this message]
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
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

  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=87vaxywmh9.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=clement.pit@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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).