unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Nicolas Petton <nicolas@petton.fr>
Cc: "Clément Pit--Claudel" <clement.pit@gmail.com>, emacs-devel@gnu.org
Subject: Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams
Date: Fri, 16 Sep 2016 00:30:28 +0200	[thread overview]
Message-ID: <87bmzoaj97.fsf@web.de> (raw)
In-Reply-To: <87mvj9ftb0.fsf@petton.fr> (Nicolas Petton's message of "Thu, 15 Sep 2016 10:42:11 +0200")

[-- Attachment #1: Type: text/plain, Size: 357 bytes --]

Nicolas Petton <nicolas@petton.fr> writes:

> I agree, the patch is good as it is now, I'd like to have it
> installed.

Done.

FWIW, if you would like me to push this: I have implemented the sliding
window algorithm as suggested by John, but commented it out, and added a
(hopefully not too wordy) note why we raise an error for now for
negative indexes:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: stream-add-a-comment.patch --]
[-- Type: text/x-diff, Size: 2234 bytes --]

From df5652f68fc0ca6730b3f830e805cf7e30e5615d Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Fri, 16 Sep 2016 00:14:28 +0200
Subject: [PATCH] Add a comment to last change in stream.el and bump version

---
 packages/stream/stream.el | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/packages/stream/stream.el b/packages/stream/stream.el
index 9954fc8..db00b0d 100644
--- a/packages/stream/stream.el
+++ b/packages/stream/stream.el
@@ -4,7 +4,7 @@
 
 ;; Author: Nicolas Petton <nicolas@petton.fr>
 ;; Keywords: stream, laziness, sequences
-;; Version: 2.2.1
+;; Version: 2.2.2
 ;; Package-Requires: ((emacs "25"))
 ;; Package: stream
 
@@ -237,11 +237,24 @@ START on.  Both START and END must be non-negative.  Since
 streams are a delayed type of sequences, don't signal an error if
 START or END are larger than the number of elements (the returned
 stream will simply be accordingly shorter, or even empty)."
-  (when (or (< start 0) (and end (< end 0)))
-    (error "seq-subseq: only non-negative indexes allowed for streams"))
-  (let ((stream-from-start (seq-drop stream start)))
-    (if end (seq-take stream-from-start (- end start))
-      stream-from-start)))
+  (if (or (< start 0) (and end (< end 0)))
+      ;; We could return something like this (for START and END < 0):
+      ;;
+      ;; (let ((cropped stream))
+      ;;   (cl-dotimes (_ (- start)) (stream-pop cropped))
+      ;;   (while (not (stream-empty-p cropped))
+      ;;     (stream-pop stream)
+      ;;     (stream-pop cropped))
+      ;;   (seq-take stream (- end start)))
+      ;;
+      ;; but we are not sure whether advertising negative indexes is a good
+      ;; idea: this would potentially create a bunch of thrown away objects,
+      ;; and "searching from the end" might be better in most use cases.  So
+      ;; we raise an error instead:
+      (error "seq-subseq: only non-negative indexes allowed for streams")
+    (let ((stream-from-start (seq-drop stream start)))
+      (if end (seq-take stream-from-start (- end start))
+        stream-from-start))))
 
 (cl-defmethod seq-into-sequence ((stream stream))
   "Convert STREAM into a sequence."
-- 
2.9.3


[-- Attachment #3: Type: text/plain, Size: 11 bytes --]



Michael.

  reply	other threads:[~2016-09-15 22:30 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
2016-09-15  8:42               ` Nicolas Petton
2016-09-15 22:30                 ` Michael Heerdegen [this message]
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=87bmzoaj97.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=clement.pit@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=nicolas@petton.fr \
    /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).