Simple file I/O
October 28, 2009by Lee Spector (lspector)
If you want to read things from files into Scheme, or to write things to files from Scheme, there are a lot of built in procedures to use and a lot of approaches you could follow, but the simplest idea is to read and write single Scheme objects, which could be arbitrarily big things if you use nested lists. Here’s an example:
(define data '((here are some symbols (and also "a string")) ((2009 10 20 11 34) "Numbers in the car of the list of which I'm the cadr.") (more stuff))) (define save-data (lambda () (with-output-to-file "myData.txt" (lambda () (print data)) #:exists 'replace))) (define read-data (lambda () (with-input-from-file "myData.txt" (lambda () (set! data (read))))))
November 16th, 2009 at 8:27 am
[…] Simple file I/O […]