[plt-scheme] copy-port and custom-port

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jul 23 14:32:35 EDT 2008

At Wed, 23 Jul 2008 11:20:36 -0700, YC wrote:
> ;; afile.ss ;; (load "afile.ss")
> ;; provide read closure over the wrapped port
> (define (read-in port)
>   (lambda (bytes)
>     (let* ((len (bytes-length bytes))
>            (bytes-in (read-bytes len
>                                  port)))
>       (cond ((eof-object? bytes-in) eof)
>             (else
>              (bytes-copy! bytes 0
>                           bytes-in)
>              len)))))

You should return `(bytes-length bytes-in)' here, not `len'.

> ;; provide peek closure over the wrapped port
> (define (peek-in port)
>   (lambda (bytes skip progress-evt)
>     (let* ((len (bytes-length bytes))
>            (peeked (peek-bytes len
>                                skip port)))
>       (cond ((eof-object? peeked) eof)
>             (else (bytes-copy! bytes 0
>                                peeked)
>                   len)))))

Similarly, return `(bytes-length peeked)'.



Matthew



Posted on the users mailing list.