emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations


From: Michael Heerdegen
Subject: Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations
Date: Thu, 02 Mar 2017 03:36:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Hi everybody!

I want to revive this discussion.  I needed something like this for
el-search, so I gave it a second thought.

> >> As an example, if you want a subsequence starting at the first odd
> >> number or at index 1000, whichever is earlier, (seq-drop (min 1000
> >> (seq-position-if 'odd S)) S) will not do the right thing.
> >
> > Would adding an optional argument that allows to specify an upper limit
> > for the indexes the function looks at cover (all of) your concerns?
>
> That was just an example. Real users will have other needs. If given a
> primitive that returns an index of something, they will try solving
> their problems in terms of that index. It is an interface that is easy
> to use incorrectly.
>
> But please do not let my theoretical concerns stop you from
> implementing useful things. A working implementation is the surest way
> of gaining collective experience about a tool.

I tried to cope with our problems by using abstraction and higher order
functions (so far, only implemented for streams - see below).

We talked about pairs of function (take-until, drop-until), and a
problem was that the semantics were always a bit vague or hard to define
(is a border element in or out?, etc).  A difficulty with the discussed
concepts was that it was not easily possible to step back to cut a
stream before a certain element when we already had skipped that element
etc.

That brought me to the following idea:

The underlying basic "operation" is to divide a stream into two parts.
Such a division is non-ambiguously described by specifying the second
part, the rest-stream.  Any function dividing a stream into two parts
can be described by another function F stream -> rest, that takes a
stream, and returns a rest.  Such functions F are the input of my
low-level functions.

A subsequent application of divide operations leads to a partition of a
stream into a stream of substreams, which I also implemented.

I also implemented two more higher-level functions for stream
dividing/partitioning that hopefully should cover most of the use cases
of seq-drop-while et alter.  For the cases that should not be covered,
you can use the lower level functions with an appropriate function F as
described above.  Sounds complicated, but it's just a sum of trivial
pieces.

And this is how that looks.  WDYT?

Attachment: stream-divide.el
Description: application/emacs-lisp


Regards,

Michael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]