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.
Previous article: Integers
Next article: Characters
Comments
Have something to write? Comment on this article.
Hi Brett,
Thanks for the input.
1) Why such a restrictive license on something so academic? I don’t really mind, it’s just an odd choice.
I did think about licensing for a while. I chose the AGPL because I believe in the freedoms it ensures users.
2) Git tags seem perfect (more correct) for what you’re using branches for.
The branches are not static. I have evolved them already to keep all the branches in sync in cases where I encounter a pedagogical roadblock and need to backtrack through the branches.
Have something to write? Comment on this article.
Thanks for this, I’m happily following along. Two things though,
1) Why such a restrictive license on something so academic? I don’t really mind, it’s just an odd choice.
2) Git tags seem perfect (more correct) for what you’re using branches for.