chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] stream trouble


From: Shawn Rutledge
Subject: Re: [Chicken-users] stream trouble
Date: Tue, 4 Oct 2005 00:06:17 -0700

On 10/3/05, Alejandro Forero Cuervo <address@hidden> wrote:
> wiki->html expects a stream of characters to operate on, not a port.
> You can use port->stream to get a stream with all the characters on a
> given port; characters will be read from the port as they are taken
> from the string.  Thus, your example could work like this:
>
> #;1> (use stream-wiki)
> ; ...
> #;2> (stream->string (wiki->html (port->stream (open-input-file 
> "/tmp/index.wiki"))))
> "<p>This is a <a href='test' class='internal'>test</a>.</p>"
>
> BTW, you may be confused by (stream? ins) returning #t in your
> example (and the error being caught by stream->string rather than
> wiki->html).  This is normal due to the lazy semantics of streams.

Yep that works, thanks.

So to use it from an .ssp I have this:

<?scheme
    (require-extension stream-wiki)
    (define inp (open-input-file "/var/www/localhost/htdocs/wiki/index.wiki"))
    (display (stream->string (wiki->html (port->stream inp))))
?>

But it has to allocate the entire string whereas I'd rather "stream"
the stream out the TCP connection in chunks.  So I try this:

<?scheme
    (let ([inp (open-input-file "/var/www/localhost/htdocs/wiki/index.wiki")])
        (require-extension stream-wiki)
        (let loop ([hstr (wiki->html (port->stream inp))])
            (unless (stream-null? hstr)
                (display (stream-car hstr))
                (loop (stream-cdr hstr)))))
?>

But if it really sends a character at a time over TCP, it won't be
very efficient network-wise, and anyway even if it's buffered, maybe
each call to display is a system call?




reply via email to

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