[racket] problem with Port Events and make-limited-input-port
On Fri, Jun 17, 2011 at 05:33:56PM +0100, milo arvidsson wrote:
> (I'm using the latest build: mz-bin-i386-win32; version 5.1.1.6,
> updated Friday, June 17 2011, 03:50 EDT)
>
> I've written versions of the following program using limited file,
> string, and pipe ports with read-bytes-line-evt, read-char-evt,
> read-line-evt, read-bytes-evt, read-string-evt, and regexp-match-evt.
> None of the port events returned #<eof> after 4 bytes were read.
>
>
> #lang racket/base
>
> (require racket/port)
>
> ;The input port is limited to 4 bytes, or just 2 lines.
> (parameterize ((current-input-port (make-limited-input-port
> (open-input-string "A\nB\nC\nD\n") 4)))
> (list
> (list (sync (read-bytes-line-evt (current-input-port)))
> (file-position (current-input-port)))
> (list (sync (read-bytes-line-evt (current-input-port)))
> (file-position (current-input-port)))
> (list (sync (read-bytes-line-evt (current-input-port)))
> (file-position (current-input-port)))
> (list (sync (read-bytes-line-evt (current-input-port)))
> (file-position (current-input-port)))))
>
> ;returns with: '((#"A" 2) (#"B" 4) (#"C" 6) (#"D" 8))
Just a guess:
Could it be that the input port has five characters to pass on to you,
including the '\n' at the end, so it really isn't finished yet after
just 4?
-- hendrik