[plt-scheme] file access and scope

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue May 8 09:48:14 EDT 2007

You may want to skim this http://www.ccs.neu.edu/home/matthias/HtUS/ 
Book/howto.html or the older version (htus.org). Neither are recent.  
-- Matthias


On May 8, 2007, at 9:43 AM, SpinyNorman wrote:

> 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")))
>     (begin
>       (file-position fd)
>       (display (read-line fd 'any))))
> bar
>
> There is a file in the current directory named "foo," containing the
> word, "bar."
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.