Scheme from Scratch - Royal Scheme v0.1 - Integers

It took a while but the plan is back on track. Royal Scheme is a go.

I’ve been picking away at the project at a leisurely pace trying to determine exactly what it will be. Blog articles seem like a great way to keep folks informed about the state of development. Hopefully some folks will want to follow along creating their own implementations again like they did with Bootstrap Scheme. It was a whole bunch of fun.

I think a book format would be a better format for truly documenting the iterative development of a real Scheme interpreter that is implemented in C. I still haven’t found that book and if I was taking a university course then I’d want to take the course that has that book as its primary text. So a lot of what Royal Scheme development will be about is ensuring the order of introducing features is just right and that the concepts underlying the implementation are explained in code comments and in a book. It is a lofty goal. We’ll see how it goes. I’m hoping for feedback from you.

Just as Bootstrap Scheme started with integers, so does Royal Scheme.

$ ./scm
Welcome to Royal Scheme. Ctrl-c to exit.
> 123
123
> -123
-123
> +007
7
> ^C
$

I’ve put the code on github. I’m new to git and github which adds a bit more flavor to the project. You can browse the code at the following address

http://github.com/petermichaux/royal-scheme

and I created a branch specifically for this integers-only version

https://github.com/petermichaux/royal-scheme/tree/v0.1

You can get the code with the following command

$ git clone https://github.com/petermichaux/royal-scheme.git

You should be able to just run make and then the above REPL session example should work.

I’m hoping you will scrutinize the code and really give me grief that I’ve done something silly, stupid, overly complex, have a trailing space on a line, haven’t written a comment where a comment would be helpful, etc. I’m particularly interested in what you think of checking the return value of printf and scm_write in repl. It doesn’t feel right quite to me. Also the overflow checking in scm_read_number happens each iteration which is not as efficient as it possibly could be.

By the way, registration for the Scheme 2011 Workshop will open in August. I’m planning on going and hoping to talk with some people there about Royal Scheme.

Previous article: Introduction

Comments

Have something to write? Comment on this article.

Jim Ingram July 30, 2011

I’ll be following along with my own implementation, like I did with the Boostrap Scheme articles. Hopeful there will be some familiar faces from before that are doing the same (and new faces as well). My project is also on GitHub (https://github.com/ingramj/rescheme), and I’ve been getting very helpful feedback from Peter.

As for checking the return value of printf, I don’t think it’s worth it. It’s worth checking the return value of fprintf, if you’re (possibly) writing to a regular file, and not stdout or stderr.

Peter Michaux July 30, 2011

Jim,

Imagine if the REPL is controlling a life support system. If scm_write only prints part of its output due to some temporary problem then you might make a bad decision based on what you see as the result of evaluating an expression. In this case, exiting does not seem like the right thing to do.

Chris S. August 8, 2011

I had almost given up hope that this project would make it off the ground. I’ve been playing around with the idea for a while now, working from a GC/VM perspective back towards the REPL/Compiler (https://github.com/arlaneenalra/insomniac). The last incarnation of this gave me quite a few hours of interesting problem solving time. It will be intriguing to see how this one turns out :).

Have something to write? Comment on this article.