[plt-scheme] why does input port close?

From: David B. Tucker (dbtucker at cs.brown.edu)
Date: Tue Nov 19 12:54:26 EST 2002

I don't understand the behavior of the following program:

(define (input-port->line-stream in)
  (letrec ([next-line (lambda ()
                        (let ([line (read-line in)])
                          (if (eof-object? line)
                              (cons line next-line))))])

(define a (input-port->line-stream (current-input-port)))

(define b (call-with-input-file "/home/dbtucker/A.hs" input-port->line-stream))

The call to (a) succeeds, but the call to (b) gives this error:

  read-char: input port is closed

Why is that?  Thanks,


Posted on the users mailing list.