After a few years of programming it seems time to finally attack SICP. However, instead of editing and running everything in Emacs, I’d rather use a different editor and a simple makefile to run all the exercises. This doesn’t seem to be entirely canon, because I couldn’t find any reference to something as basic as running a file until something “fails”. So how do I run Scheme on the shell so that it loads a file, evaluates each expression in sequence, and terminates with a non-zero exit code as soon as it encounters a statement which evaluates to #f or with an exit code of zero if the entire file was evaluated successfully? The closest thing to a solution so far:
$ cat ch1.scm
...
(= 1 2)
$ scheme --load ch1.scm
...
Loading "ch1.scm"... done
1 ]=>
Edit: In other words, is there some way to make evaluation stop during the loading of ch1.scm if any of the expressions therein evaluate to #f?
One option if you don’t want to resort to a full-blown unit-testing library (understandable) is to write your own. You can use
readto read s-expressions from the file, useevalto evaluate them and test if they are false, and report back, quitting if you find a false. Something like this should work:If you put the above in a file called
unit.scmand the file you want to test is calledtest.scm, you can call this with MIT Scheme from the Unix command line like so:(note there’s some MIT Scheme specific things above, related to
evaland enviroments)