[racket] problem with Port Events and make-limited-input-port

From: milo arvidsson (miloarvidsson at gmail.com)
Date: Fri Jun 17 12:33:56 EDT 2011

(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))


The following version uses 'read-bytes-line' and works as expected:

#lang racket/base

(require racket/port)

(parameterize ((current-input-port (make-limited-input-port
(open-input-string "A\nB\nC\nD\n") 4)))
  (list
   (list (read-bytes-line) (file-position (current-input-port)))
   (list (read-bytes-line) (file-position (current-input-port)))
   (list (read-bytes-line) (file-position (current-input-port)))
   (list (read-bytes-line) (file-position (current-input-port)))))

;returns: '((#"A" 2) (#"B" 4) (#<eof> 4) (#<eof> 4))


Posted on the users mailing list.