[plt-scheme] copy-port and custom-port
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