emacs-devel
[Top][All Lists]
Advanced

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

Re: [ANN] New library stream.el in ELPA


From: Michael Heerdegen
Subject: Re: [ANN] New library stream.el in ELPA
Date: Wed, 14 Oct 2015 14:37:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Nicolas Petton <address@hidden> writes:

> 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.

FWIW, I implemented quite the same some years ago, but never got happy
with it.

The problem was that streams defined via delayed conses end up to be
massively nested lambda structures.  Emacs has no tail recursion, and
sooner or later, I always ended with very simple examples, like
computing the 500nth prime in the stream of primes, hitting the
`max-lisp-eval-depth' limit.  I don't recall the details of a
counterexample, but I ended up dismissing the approach completely,
because it was hopeless.

Then I switched to working with generator.el, and defined a different
form of streams I called "ilists".  These are like normal lists, but
(speaking simplified) the last cdr contains a rule to compute more
elements on the fly when they are referenced.  That approach gives you a
quite similar kind of semantical thing offering the same functionality,
without the deadly recursion problem.

My fear is that you will soon see `max-lisp-eval-depth' related errors
when doing very simple things with your streams and trying to reference
element 500 or so.  Sorry, but I really don't recall a good
counterexample.  It would be great if I'm proven wrong by your
implementation, but I'm not optimistic.

I tried with your package

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

(seq-elt (fib 0 1) 10)

but got the error

unless: Symbol’s value as variable is void: #:forced


Regards,

Michael.




reply via email to

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