Scheme from Scratch - Bootstrap v0.17 - And and Or
One more round of library syntax: the
or forms. These could be split into two different versions but they are so similar I think biting them off in one chunk is justified. If you do
and first then
or will be easy.
Sample REPL session:
$ ./scheme Welcome to Bootstrap Scheme. Use ctrl-c to exit. > (and 1 2 3) 3 > (and) #t > (or #f 2 #t) 2 > (or) #f
An important aspect of
or is they are short-circuiting. Here is an example demonstrating the importance of
and short-circuiting when side-effects are involved:
> (define a 1) ok > (and #f (set! a 2)) #f > a 1 > (and #t (set! a 2)) ok > a 2
If you are not already consulting the Scheme spec when implementing features in your interpreter, now might be a good time to give that a try. I have R5RS printed on real paper which is handy.
I’m not 100% sure but I think it might now be possible to run all the examples in The Little Schemer in your interpreter.
I’ve enjoyed the watch feature on GitHub to follow other’s progress. It is motivating to see implementations moving forward and really great to see people have actually implemented features I haven’t discussed yet:
There is a v0.17 branch on github for this version.
Have something to write? Comment on this article.