Scheme from Scratch - Bootstrap v0.20 - I/O
The last major missing piece of the puzzle for a bootstrap interpreter is the ability to work with files. Scheme has several input and output primitive procedures and I’m implementing the ones I think will be useful. It is a slightly larger amount to implement than some days have been but hopefully quite straightforward for anyone who has come this far.
A sample REPL session:
$ ./scheme Welcome to Bootstrap Scheme. Use ctrl-c to exit. > (define out (open-output-port "asdf.txt")) ok > (write-char #\c out) ok > (close-output-port out) ok > (load "program.scm") program-loaded > (error "bad move") "bad move" exiting
Some of these functions required refactoring in other areas of the interpreter. I refactored the C
read function to handle the end of a source file properly. I refactored the C
write function to take a stream parameter so that the Scheme
write could write to any port. I’ll backport these changes to previous versions eventually.
I’m not doing any of the the
with-input-from-file business. If a port is not specified as an optional parameter to
write-char, etc then C’s
stdout are used.
I added the
error output form which
writes all of its arguments and then exits. This form is not required by R5RS, for example, but is useful.
There is still a little bit to do but we are oh so close.
There is a v0.20 branch on github for this version.
Have something to write? Comment on this article.