emacs-devel
[Top][All Lists]
Advanced

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

[ANN] New library stream.el in ELPA


From: Nicolas Petton
Subject: [ANN] New library stream.el in ELPA
Date: Wed, 14 Oct 2015 13:43:06 +0200
User-agent: Notmuch/0.19 (http://notmuchmail.org) Emacs/25.0.50.7 (x86_64-unknown-linux-gnu)

Hi,

I just pushed to ELPA the first version of `stream', a new library that
provides an implementation of streams. Streams are implemented as
delayed evaluation of cons cells, and are immutable. In that sense they
are similar to streams in the SICP book[1] or to Clojure's lazy
sequences.

`stream' requires Emacs >= 25.1, as it leverages the extensibility of
seq.el (the version currently in master, not the one in ELPA): all
functions defined in seq.el will work on streams, meaning that it's
possible to consume a stream using `seq-take', map and filter it using
`seq-map` and `seq-filter`, and so forth.

Streams could be created from any sequential input data:
 - sequences, making operation on them lazy
 - a set of 2 forms (first and rest), making it easy to represent infinite 
sequences
 - buffers (by character)
 - buffers (by line)
 - buffers (by page)
 - IO streams
 - orgmode table cells
 - ...

The generic `stream' function currently accepts lists, strings, arrays and
buffers as input, but it can be cleanly extended to support pretty much any kind
of data.

All operations on streams are lazy (including the functions from seq.el), unless
data is actually needed.

Here is an example implementation of the Fibonacci numbers
implemented as in infinite stream:

    (defun fib (a b)
      (stream-cons a (fib b (+ a b))))
    (fib 0 1)

The following example returns a stream of the first 50 characters of the
current buffer:

    (seq-take (stream (current-buffer)) 50)
      

Cheers,
Nico

[1] https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5

Attachment: signature.asc
Description: PGP signature


reply via email to

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