(write the-data (open-output-file "data.scm")) ? =)<div><br></div><div>Generally though, you're better off with with-input-file and with-output-file , as the return of the thunk communicated explicitly to Gambit's IO system, that the port is no longer used, i.e. (with-input-from-file "data.scm" read) / (with-output-to-file "data.scm" (lambda (p) (write your-data p))).</div>

<div><br></div><div>Also of course you could do (let* ((p (open-input-file "data.scm")) (d (read p))) (close-port p) d) , but you see it's less concise. (Also, what if read would throw an exception, clearly this variant does not come with any finalization of p - would with-intput-from/to-file finalize them? - anyone is free to clarify this.)</div>

<div><br></div><div>Just dropping the file handle will wait for it to garbage-collect away, which generally is really fine but potentially could bring problems (say that you'd unintentionally do 10 000 file operations like that prior to a GC, that would generally cause the OS to run out of file descriptors and you'd get more or less weird error messages).</div>

<div><br></div><div>Also note that with this kind of very high level resources, you cannot expect them to be automatically GC:ed away. Thread objects for instance, at least if they're running, are not GC:ed away. With file ports, I'd believe they are. With TCP ports, not clear. Anyone is free to bring clarity to this one too.</div>

<div><br></div><div>Best regards<br><br><div class="gmail_quote">2012/10/27 Richard Prescott <span dir="ltr"><<a href="mailto:rdprescott@gmail.com" target="_blank">rdprescott@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Good morning everybody,<br>
<br>
Forgive my ignorance, I am just learning.<br>
<br>
In order to embrace the "code is data" philosophy [1], I want to load and save data as s-expressions within files.  I figured the load using (read (open-input-file "data.scm")).<br>
<br>
How can I save?<br>
<br>
Thanks in advance.<br>
<br>
Richard<br>
<br>
<br>
[1]: I just learnt that it is called <a href="http://en.wikipedia.org/wiki/Homoiconicity" target="_blank">http://en.wikipedia.org/wiki/Homoiconicity</a><br>
_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
</blockquote></div><br></div>