[plt-scheme] file access and scope

From: SpinyNorman (jmcaxolotl at gmail.com)
Date: Tue May 8 09:43:02 EDT 2007

I'm using Dr Scheme, and trying to get familiar with how to read data
from a file.  Some or all of what I "know" may be wrong.  I have been
using let to capture the return from open-input-file, which I can then
pass to file-position or read-line, etc.  But when the let finishes,
and I'm back at the ">" prompt, the symbol holding the reference to
the input port is gone.  Two questions come to mind.  One, is the file
now closed, or am I holding another port open every time I call some
newly tweaked version of the let?  Two, if the port remains open, is
there a way I can refer to it?  Or even see what open ports there are?

In case that description of what I'm doing is too abstract, here's the
tiny bit of code I'm talking about:

> (let ((fd (open-input-file "foo")))
      (file-position fd)
      (display (read-line fd 'any))))

There is a file in the current directory named "foo," containing the
word, "bar."

Posted on the users mailing list.