Ah Richard, note that all of these four file output/input routines mentioned now, can take a settings structure argument in the place where you passed filenames up to now. Using those settings, you can specify things like character encoding to use for the read/written file.<br>

<br><div class="gmail_quote">2012/10/27 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
Le 2012-10-27 à 4:31 AM, Richard Prescott <<a href="mailto:rdprescott@gmail.com">rdprescott@gmail.com</a>> a écrit :<br>
<div class="im"><br>
> 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>
</div>While it does work, your code does not close the input-port and relies on the garbage collector to do this, which is a bad idea (because you may run out of file descriptors before a garbage collection is triggered).  It is better to use call-with-input-file which closes the port.<br>


<br>
Here are better save and restore functions:<br>
<br>
;; File: save-restore.scm<br>
<br>
(define (save-to-file filename obj)<br>
  (call-with-output-file<br>
    filename<br>
    (lambda (port) (write obj port))))<br>
<br>
(define (restore-from-file filename)<br>
  (call-with-input-file<br>
    filename<br>
    (lambda (port) (read port))))<br>
<br>
(save-to-file "data.txt" '#(1 2 3))<br>
<br>
(pp (restore-from-file "data.txt"))<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
Marc<br>
</font></span><div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br>