[Top][All Lists]

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

Re: [Chicken-users] ANN: lazy-seq, a port of Clojure's lazy sequence API

From: Alex Shinn
Subject: Re: [Chicken-users] ANN: lazy-seq, a port of Clojure's lazy sequence API
Date: Sun, 3 Jun 2012 16:48:16 +0900

On Sun, Jun 3, 2012 at 4:05 PM, John Cowan <address@hidden> wrote:
> Peter Danenberg scripsit:
>> Stream-cons, stream-lambda, &c. are so fucking verbose!
> Only two letters longer than lazy-length, lazy-map, lazy-head, lazy-tail, etc.
> Why not a macro with-lazy that rewrites car, cdr, lambda, cons, etc. within
> its body?

Unhygienic!  Heathen!


Although you have the right idea.

First, the srfi-41 vs. lazy-seq comparison in the
blog post was an apples to oranges comparison
of a clumsy letrec vs a compact named let.  If we
rewrite the srfi-41 version in the same style as
the lazy-seq one, then we get:

(define multiples-of-three
  (let next ((n 3))
    (stream-cons n (next (+ n 3)))))

This is actually more compact - just _remove_
the lazy-seq reference, and s/cons/stream-cons/.

Now, if we have a whole program or library which
consistently uses lazy streams instead of lists,
we can import srfi-41 renaming all the stream-*
bindings by removing the stream- prefix (this is
where the drop-prefix you like comes in handy).
Then you have a normal Scheme library using
car/cdr/cons etc. which happens to be using
streams (and you could change the import if
needed to toggle between the two).

Introducing an extra syntactic wrapper just makes
this more complicated.


reply via email to

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