Schemette

Introduction

Quite simply: Schemette is a Scheme interpreter written in C++ and designed to be fast, easy, and portable. It does NOT have a GUI (nor do I plan on adding that anytime soon); it is based on the command line. It will include both an interactive listener as well as a file processor.

The inspiration

Okay, so it wasn't entirely original. We're working with Scheme in my intro computer science class, and one of our projects was to implement a Scheme interpreter (in Scheme). That was of course interesting, but I thought it would be even more useful to write one in a language I already know some other things about, but which is fundamentally different from Scheme (namely, C++). Specifically, I want to take advantage of the power that polymorphism has to offer in writing an evaluator for Scheme expressions.

We called that class project Schemeleh (Yiddish for "dear little Scheme"), and along those same lines I came up with the (also unoriginal) name "Schemette" for my implementation.

Current status

Below is a table of Scheme constructs, listing which have been implemented, which will be implemented, and which won't. Keep in mind that even those that technically "won't" get put into schemette may end up part of it. It really just means that no major effort is being put into including them.


Feature Status* Comments and Sample Tests

Changing Environments

define I (define foo 3)
(define bar (lambda (x) x))
(define har (lambda (x) (lambda (y) (+ x y))))
lambda I (lambda (x) 5) ;; returns a procedure
(lambda (x) x)
let B (let ((a 5) (b 3)) (+ a b)) ;; should be 8
letrec N/A N/A

Conditionals

if I (if #t 1 0) ;; should be 1
(if #f 13 (quote smokey)) ;; should be smokey
(if (zero? foo) (bar foo) foo) ;; should be 0
cond N/A N/A

Language features

Simple procedure application I ((lambda (x) 5) 3) ;; should be 5
((lambda (x) x) 7) ;; should be 7
(bar 12) ;; should be 12 (assuming bar define'd as above)
Recursion B (define fib (lambda (x) (if (<= x 2) 1 (+ (fib (- x 1)) (fib (- x 2))))))
(fib 5) ;; 5th Fibonacci number.
;; Currently fails for some reason I do not
;; understand. Car/Cdr recursion is fine.
Closures I ((har 3) 7) ;; should be 10
(((lambda (x) (lambda (y) (+ x y))) 5) 17) ;; should be 22

Syntactic Sugar

Comments I ;; skip evaluation till end of line
quote I (quote (1 2 3)) ;; should be (1 2 3)
(quote baz) ;; should be baz
Quick quote (') N/A '(1 2) ;; should be (1 2)
Square brackets B (let [(a 5) (b 3)] (+ a b)) ;; should be 8
;; unbalanced paren's should check the type
;; (regular vs. square)

Built-in operators

car I (car (quote (1 2 3))) ;; should be 1
(car (quote ((5 6) 7 8 9))) ;; should be (5 6)
(car (quote ())) ;; should barf with accurate message
(car 5) ;; ditto
cdr I (cdr (quote (1 2 3))) ;; should be (2 3)
(cdr (quote ((5 6) (7 8 9) (10 11))))
;; should be ((7 8 9) (10 11))
(cdr (quote ())) ;; should barf with accurate message
(cdr 7) ;; ditto
+ I (+ 3 5) ;; should be 8
(+ 2.2 5) ;; should be 7.2
(+ 6) ;; should be 6
(+ 3 -2) ;; should be 1
(+) ;; should be 0
(+ 12 4 16 -3 -20 7.2 5 -16.5) ;; should be 4.7
- I (- 5 2) ;; 3
(- 6.2 -3.4) ;; 9.6
<= I (<= 5 2) ;; #f
(<= 2 5) ;; #t
(<= 3 3) ;; #t

Built-In Types

Boolean I #t
#f
List I (3 5 1) ;; cannot actually evaluate this
(quote (3 5 1))
(+ 3 8) ;; 11
Number B ;; not quite arbitrary precision-point, but maybe
;; as good as it will get.
4.2
6
-13.7
3.14159265
2.718281828459045
Procedure I (lambda (x) x) ;; see above for more examples
String B "foo"
Symbol I foo

* Statuses in italics are currently being worked on. Designations:

Currently working on

What's Next

Back to Projects

Back to Phoenix Web Home.


Phoenix-webmaster: Dave Pacheco
Last updated 2003-01-28