Scheme from Scratch - Bootstrap v0.8 - Quote

Today we change our focus to the evaluate layer and the REPL really starts to come alive as a real interpreter of the Scheme language.

So far the REPL has been a pretty printer. The empty list, pairs, lists, symbols have been auto-quoting and echo back to you. By adding the quote form we can end that pretty printing and have a proper REPL session:

$ ./scheme
Welcome to Bootstrap Scheme. Use ctrl-c to exit.
> (quote a)
a
> 'a
a
> (quote (0 1 2))
(0 1 2)
> '(0 1 2)
(0 1 2)
> '()
()
> ()
> '#t
#t
> #t
#t
> '123
123
> 123
123
> '#\c
#\c
> #\c
#\c
> '"asdf"
"asdf"
> "asdf"
"asdf"

You can see above that booleans, numbers, characters and strings are auto-quoting. If you try to enter just the empty list, a pair, list, or symbol the REPL will error as the evaluate layer doesn't know what to do with them yet.

When you look in the implementation. You will see that the single quote syntax is converted to a quote form directly in the read layer of the interpreter.

There is a v0.8 branch on github for this version.

Previous article: Symbols
Next article: Environments

Comments

Have something to write? Comment on this article.

Nick Fitzgerald January 13, 2010

Awesome!

I have been following the series the whole time (and submitting to HN for others to enjoy as well) and I only just found some time to start actually coding along. I don't really know C very well, but I am alright with Ada, so I thought I would learn me some C by porting your code to Ada.

So far I have only done v0.1, but I plan to catch up in the next few days or week or so.

Thanks a lot for doing this and sharing, I was actually in the middle of attempting to write my own micro-language for fun when you started this series, but I feel I’m just not far enough along in my CS degree to quite fit every puzzle piece together. Having your code to work with and study has been really awesome so far.

Here is my Ada bootstrap scheme so far: http://github.com/fitzgen/ada-scheme

Cheers,
Nick

Have something to write? Comment on this article.