From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams Date: Fri, 16 Sep 2016 00:30:28 +0200 Message-ID: <87bmzoaj97.fsf@web.de> References: <87bmzrahvg.fsf@web.de> <79c6ccd6-9808-f4fd-071a-58559f72ecdc@gmail.com> <8737l3a4ab.fsf@web.de> <27962aa1-ae40-99f8-64ad-ae21012fb36e@gmail.com> <87vaxywmh9.fsf@web.de> <87zina568j.fsf@web.de> <63ebf6ee-d623-e863-42a8-bc802d3df54d@gmail.com> <87mvj9ftb0.fsf@petton.fr> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1473978662 17092 195.159.176.226 (15 Sep 2016 22:31:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 15 Sep 2016 22:31:02 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: =?utf-8?Q?Cl=C3=A9ment?= Pit--Claudel , emacs-devel@gnu.org To: Nicolas Petton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 16 00:30:55 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkfBE-0003as-9y for ged-emacs-devel@m.gmane.org; Fri, 16 Sep 2016 00:30:52 +0200 Original-Received: from localhost ([::1]:37759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkfBB-0004Wn-Mn for ged-emacs-devel@m.gmane.org; Thu, 15 Sep 2016 18:30:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkfB4-0004Wg-WC for emacs-devel@gnu.org; Thu, 15 Sep 2016 18:30:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkfB0-0004wk-IG for emacs-devel@gnu.org; Thu, 15 Sep 2016 18:30:41 -0400 Original-Received: from mout.web.de ([217.72.192.78]:55763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkfB0-0004w5-2r for emacs-devel@gnu.org; Thu, 15 Sep 2016 18:30:38 -0400 Original-Received: from drachen.dragon ([90.186.1.83]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0Maayz-1bQfLd3s6L-00K5A8; Fri, 16 Sep 2016 00:30:34 +0200 In-Reply-To: <87mvj9ftb0.fsf@petton.fr> (Nicolas Petton's message of "Thu, 15 Sep 2016 10:42:11 +0200") X-Provags-ID: V03:K0:C9siXrUDLLDy24hLzk44PQjFfytLlc/p+qtHwrauG/NQPU5E09B y2t2qi+FWAQIkPHGYvd1v4MerXKzgVweg71BtbYKYCNOq8taEBgKDkklHEvNiVQph5ieMva ZgX9gOKE/MxUcA2wL1uKTvRXdUSDcq+91YWVfUhPM1tspzGRzcIF3Jfx5sDwJrX26k/fq4S Xl6D6NGLfZwiyLxx+ON6Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:xzGAIDI9P2M=:x0jbAKi2GnWxEudm6FzGPu Ze4Z9/su5JSyT1v+L3QOfg3RcNsn7zYoqxHbNKatax011Ha1FQgeGhyBY2PBDXKaDgTlJsoQT wWpLAbmzp3IFjP06hWC3bDx9EK8GIllkRjXgceWwLVMveT+0njowWTdR8/pj+TgsJVY/+eyOl 7g1eeSY0nNZ7/D/vPM+UW9ZCZEjQtHa62MK0dk9EsW4ZuhBVUFm/KgHgpkJpVVMt9gV40omZl 48OZs6Qnp4yNZGZDgkKsNwC1MiG4E95j5kEjgkDEJa4J99nK5RdlYj4n/MCIDf50z/QrZLFOi r/X0RTTTyTInvL97zwvg/uQlA2Qagm/jx5hK9GWiQMnva6tqoWS7RRnZFIrrSqnpn3qXfv8A4 lx9OwYX8CCH5+O/LvvcPP3Zcb+dmxamUxGG1RmmH8lADpAZm6zCvkKTw5kE6twxnHgkGx3+l/ JscupW/E1DsIUQF6RHT7wVsknzsKoQkYIxFaJBQjOPDGRh+on/AOKcCbD+LZQLotvzXbeU8QZ P/2Qs+VO2fuTwieoQSC1l9HBenyfPsMCWyYfOEk4kFgs1Fu6bvhhKAKdggV3Wxlh7akT5xV0A htO0xycKzeg4p8lBrp6niZ8J9uX3eQP8YVZjy3RDaKs7zI+mL7qQ+U9xjWfUFv3oLUt9ECm25 5r7W1dP2t/5L/6Fdzboz3gUr2R1xSpvmo/qqJTw1ieWOnJq91odSNCYqCq5jZzqCetA+VYQ4I EZ2FXwYJDzxSueU/phritHsxfmHKx1auTIZcUoAKdTjej/9fUQbdKeThb3+8bm/J0vLPhjR8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.78 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207454 Archived-At: --=-=-= Content-Type: text/plain Nicolas Petton 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=stream-add-a-comment.patch >From df5652f68fc0ca6730b3f830e805cf7e30e5615d Mon Sep 17 00:00:00 2001 From: Michael Heerdegen 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 ;; 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 --=-=-= Content-Type: text/plain Michael. --=-=-=--