chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] html-stream: idiom for large iterations?


From: Graham Fawcett
Subject: Re: [Chicken-users] html-stream: idiom for large iterations?
Date: Mon, 2 May 2005 09:42:21 -0400

On 4/30/05, Alejandro Forero Cuervo <address@hidden> wrote:
> 
> I would suggest using "stream-concatenate" instead of "apply
> stream-append" (or even "fold-right stream-append").  The only
> difference is that you wouldn't pass a list but a stream.  This has
> one advantage (that is usually minor but can, in some cases, make a
> very big difference): the information you are appending
> (concatenating) is only built as it is consumed.
> 
> Your code would thus look like this:
> 
>   (require-extension html-stream stream-ext)
>   (stream->string
>    (html-stream
>     (html (head (title "Hello, world!"))
>      (body
>       (ul
>        (stream-concatenate
>         (stream-map (lambda (x) (html-stream (li "This is item " x)))
>                     (stream-iota 1000))))))))

Thanks -- that's more consistent and readable. 

> stream-concatenate is defined in the stream-ext egg; since you are
> doing stream-append, I suppose you're already using it.

Yes. I'm coming at Scheme from a Python background, and it took me a
while to realize that streams were more like Python generators than
like input/output streams. :-)

Alejo, I'm curious about the performance characteristics of
html-stream. In my (very simple  and perhaps naive) tests, the
non-stream-based htmlprag module appears to provide much better
performance with respect to CPU time and mutations/GC than
html-stream. (Perhaps this is only on my test machines, though?)

There's more to good code than raw speed; I'm not trying to be
critical, but rather trying to understand what strengths the
streams-based approach brings to the table. Lazy evaluation is one
major benefit; are there other advantages to "thinking in streams"
that you find useful?

Regards,

-- Graham




reply via email to

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