[plt-scheme] evaluating contents of a string

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Jul 26 22:30:26 EDT 2006

At Wed, 26 Jul 2006 22:02:55 -0400, David Richards wrote:
> 
> On Jul 25, 2006, at 10:53 PM, Chris Warrington wrote:
> 
> >
> > David Richards @ 2006-7-25 10:46:15 PM
> > "[plt-scheme] evaluating contents of a string" 
> > <mid:ac01fb5e725b12548648a10157eeb98d at verizon.net>
> >
> >> Given:
> >> "(lambda () (current-seconds))"
> >> What is the 'best practice', or most elegant way to obtain a scheme
> >> procedure from the contents of a string?
> >
> > I'd use:
> > (eval (read (open-input-string "(lambda () (current-seconds))")))
> 
> 
> 
> Thanks for that, and to everyone else for all the advice.
> 
> Questions... in the example above, what happens to the input port?  
> Don't we need to close the input port explicitly?  I was under the 
> impression that unclosed ports become 'leaks' if we don't explicitly 
> close them before exiting an execution context.  Is it safe to leave a 
> port unclosed in a context that is eligible for garbage collection?  
> Does the garbage collector close ports that are left open?  If so, why 
> is there all the harsh exhortation in the documentation to close open 
> ports when finished with them?

You have to carefully close ports that hold onto OS-level resources
(like tcpip connections and files) and you often also need to close
ports to force all of the data to actually commit to the port so it is
seen on "the other end" (wherever that may be -- for example if you use
process).

Robby


Posted on the users mailing list.