From: Michael Heerdegen <michael_heerdegen@web.de>
To: Emacs Development <emacs-devel@gnu.org>
Cc: Nicolas Petton <nicolas@petton.fr>
Subject: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams
Date: Tue, 13 Sep 2016 18:23:31 +0200 [thread overview]
Message-ID: <87bmzrahvg.fsf@web.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 97 bytes --]
Hi,
I would like to install the following patch to Gnu Elpa. Does it look
ok to you, Nicolas?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Pinpoint-semantics-of-seq-subseq-s-implementation-for-streams.patch --]
[-- Type: text/x-diff, Size: 2527 bytes --]
From 77871facc3b00b8fe6d032e38c4b229d114a97ae Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Wed, 7 Sep 2016 15:45:07 +0200
Subject: [PATCH] Pinpoint semantics of `seq-subseq's implementation for
streams
- Make argument END optional.
- Forbid negative index arguments.
- Add tests.
---
packages/stream/stream.el | 15 +++++++++++++--
packages/stream/tests/stream-tests.el | 10 ++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/packages/stream/stream.el b/packages/stream/stream.el
index 8c156f1..9954fc8 100644
--- a/packages/stream/stream.el
+++ b/packages/stream/stream.el
@@ -229,8 +229,19 @@ This function will eagerly consume the entire stream."
(setq stream (stream-rest stream)))
len))
-(cl-defmethod seq-subseq ((stream stream) start end)
- (seq-take (seq-drop stream start) (- end start)))
+(cl-defmethod seq-subseq ((stream stream) start &optional end)
+ "Return a stream of elements of STREAM from START to END.
+
+END is exclusive. If END is omitted, include all elements from
+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)))
(cl-defmethod seq-into-sequence ((stream stream))
"Convert STREAM into a sequence."
diff --git a/packages/stream/tests/stream-tests.el b/packages/stream/tests/stream-tests.el
index 16b5756..31c3530 100644
--- a/packages/stream/tests/stream-tests.el
+++ b/packages/stream/tests/stream-tests.el
@@ -112,8 +112,14 @@
(should (stream-empty-p (stream-rest (stream-rest rest))))))
(ert-deftest stream-seq-subseq-test ()
- ;; TODO
- )
+ (should (equal (seq-into (seq-subseq (stream (list 0 1 2 3 4)) 1 3) 'list)
+ (seq-subseq (list 0 1 2 3 4) 1 3)))
+ (should (= (stream-first (seq-subseq (stream-range 0) 5))
+ 5))
+ (should (= (stream-first (seq-subseq (seq-subseq (stream-range 0) 5) 5))
+ 10))
+
+ (should-error (seq-subseq (stream-range 0) -1)))
(ert-deftest stream-seq-into-test ()
(should (streamp (seq-into (stream-empty) 'stream)))
--
2.9.3
[-- Attachment #3: Type: text/plain, Size: 21 bytes --]
Regards,
Michael.
next reply other threads:[~2016-09-13 16:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 16:23 Michael Heerdegen [this message]
2016-09-13 18:02 ` [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams 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
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=87bmzrahvg.fsf@web.de \
--to=michael_heerdegen@web.de \
--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).