Scheme from Scratch - Bootstrap v0.2 - Booleans
With the general structure of the integers interpreter in place, adding booleans is almost trivial: Add booleans to the model, read, and print layers.
$ ./scheme Welcome to Bootstrap Scheme. Use ctrl-c to exit. > #t #t > #f #f
The one notable difference between integers and booleans is that the true and false booleans are singletons.
When you enter
123 into the interpreter it creates a fixnum object. If you enter
123 into the interpreter again it creates another fixnum object. The two fixnum objects are still considered equal because they have the same value.
With the addition of booleans, when the interpreter starts, the model layer’s
init function is run which creates the true and false booleans. Each time you enter
#t into the interpreter no object is created. The reader just returns the true singleton object.
There is a v0.2 branch on github for this version.
Have something to write? Comment on this article.