all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Nicolas Petton <nicolas@petton.fr>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations
Date: Mon, 26 Sep 2016 00:41:02 +0600	[thread overview]
Message-ID: <CAP_d_8XC9sdEOLkOxH_t599FHf+DXmn6MN1hKrn+RPSFWT1d1w@mail.gmail.com> (raw)
In-Reply-To: <878tug9eh3.fsf@web.de>

On Sun, Sep 25, 2016 at 10:38 PM, Michael Heerdegen
<michael_heerdegen@web.de> wrote:

> If you asking the question implies that you find the semantics not
> trivially clear

Yes. Naming things is listed as the second hardest problem in computer
science, and having a concise explanation of the semantics helps with
that greatly.

> maybe the following simpler (even superior) approach
> would be much better: Add an optional integer type argument to
> `seq-drop-while' and `seq-take-while' that allows to shift the index by
> the specified amount (as far as possible):
>
> #+begin_src emacs-lisp
> (cl-defgeneric seq-drop-while (pred sequence &optional less)
>   (seq-drop sequence (- (seq--count-successive pred sequence) (or less 0))))
>
> (cl-defgeneric seq-take-while (pred sequence &optional more)
>   (seq-take sequence (+ (seq--count-successive pred sequence) (or more 0))))
> #+end_src

Let me see if I can formulate the semantics here. I will work from
cases first and then try to describe the intended behavior in a single
sentence.

seq-drop-while

* Easiest happy case: A finite number, no fewer than LESS, of initial
elements satisfy PRED. They are counted, then LESS subtracted,
yielding a non-negative count of elements to drop.

* Fewer than LESS (possibly zero) initial elements satisfy PRED. They
are counted, then LESS subtracted, yielding a negative drop count.
Presumably then seq-drop returns the original sequence.

* The sequence is infinite and its every successive element satisfies
PRED. Then the above implementation diverges, trying to count to
infinity.

My guess at intended semantics: Return the subsequence of SEQUENCE
obtained by dropping all but the last LESS initial elements that
satisfy PRED. (This does not explain the negative drop count case.)


seq-take-while

* A finite number (possibly zero) of initial elements satisfy PRED,
and after that follow at least MORE elements.

* A finite number (possibly zero) of initial elements satisfy PRED,
and after that follow fewer than MORE (possibly zero) elements.
Presumably, seq-take will return the original sequence.

* The sequence is infinite and its every successive element satisfies
PRED. The counting implementation will again diverge.

My guess: Return the initial subsequence of SEQUENCE whose elements
satisfy PRED, followed by at most MORE more successive elements.
(Another implementation can be devised that handles the infinite
case.)


Looking back at the thread, I recall that this exploration started
from my conjecture that detecting the presence of an absorbing element
could make reduction lazy wrt all following elements. The possibility
is fun to explore, but I am now thinking that was not such a useful
idea.



  reply	other threads:[~2016-09-25 18:41 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 15:42 [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations Michael Heerdegen
2016-06-02 15:50 ` Michael Heerdegen
2016-06-02 19:33 ` Nicolas Petton
2016-06-02 19:44   ` Michael Heerdegen
2016-06-08 19:52   ` Michael Heerdegen
2016-06-09 11:58     ` Nicolas Petton
2016-06-09 15:06       ` Michael Heerdegen
2016-06-09 15:46         ` Nicolas Petton
2016-06-09 16:01         ` Davis Herring
2016-06-09 16:24           ` Michael Heerdegen
2016-06-09 17:11         ` Yuri Khan
2016-06-09 19:41           ` Michael Heerdegen
2016-06-09 21:06             ` Yuri Khan
2016-06-10 15:57               ` Michael Heerdegen
2016-06-10 16:13                 ` Yuri Khan
2016-06-10 19:37                   ` Michael Heerdegen
2016-09-16 23:52                   ` Michael Heerdegen
2016-09-17  6:22                     ` Yuri Khan
2016-09-25 15:38                       ` Michael Heerdegen
2016-09-25 18:41                         ` Yuri Khan [this message]
2016-09-28  1:07                           ` Michael Heerdegen
2016-09-28  4:13                             ` Yuri Khan
2016-09-28  8:50                               ` Nicolas Petton
2016-09-28 18:27                               ` Michael Heerdegen
2016-09-28 19:19                                 ` Yuri Khan
2017-03-02  2:36                                   ` Michael Heerdegen
2017-03-02  5:00                                     ` Michael Heerdegen
2017-03-02 12:58                                       ` Nicolas Petton
2017-03-02 12:55                                     ` Nicolas Petton
2017-03-02 22:38                                       ` Michael Heerdegen
2017-03-15 14:42                                         ` Michael Heerdegen
2017-03-21 11:37                                           ` Nicolas Petton
2017-03-22 17:09                                             ` Michael Heerdegen
2017-04-21  2:34                                               ` Michael Heerdegen
2017-04-22 20:34                                                 ` Nicolas Petton
2017-04-23  5:08                                                   ` Michael Heerdegen
2017-03-20 11:29                                         ` Nicolas Petton
2016-09-25 20:49                         ` John Wiegley
2016-06-12  8:34         ` Markus Triska
2016-06-12 14:07           ` Michael Heerdegen
2016-06-12 14:31             ` Nicolas Petton
2016-06-12 22:28             ` Markus Triska
2016-06-11  1:34       ` Michael Heerdegen
2016-07-06 23:20         ` Michael Heerdegen
2016-08-01 21:13           ` Michael Heerdegen
2016-08-01 22:05             ` Nicolas Petton
2016-08-02  0:39               ` Michael Heerdegen
2016-06-09 15:48 ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP_d_8XC9sdEOLkOxH_t599FHf+DXmn6MN1hKrn+RPSFWT1d1w@mail.gmail.com \
    --to=yuri.v.khan@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    --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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.