Embeddable Scheme Interpreter
This is a tiny embeddable implementation of a strongly-typed case-sensitive Scheme dialect.
Its main advantage is that it's small (fewer than 1000 lines of C code) and easily extendable. It also has more friendly error reporting than most other interpreters (see the Examples section below).
Implemented built-in primitives include: length, list-ref, list-tail, sin, cos, tan, asin, acos, atan, ceiling, floor, truncate, round, abs, sqrt, exp, log, expt, min, max, gcd, map, reduce.
Current version is 0.9 (not yet recommended for production use) and is licensed under the 3-clause BSD license. The only prerequisite is the Boehm-Demers-Weiser GC library.
Examples ↵^
Fibonacci numbers
Program:(define fib (lambda (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))) (display (map fib '(1 2 3 4 5 6 7 8 9 10))) (newline)Output:
$ ./scheme test/fibmap.scm (1 1 2 3 5 8 13 21 34 55)
Error reporting
Helpful error messages:
> (define a (= #g #t))
SYNTAX ERROR: Line 1: Invalid constant, expected 't' or 'f':
(define a (= #g #t))
^
Checking the number of arguments to a function or primitive:
> (+ 1)
RUNTIME ERROR: Line 1: Too few arguments for '+' given, expected at least 2:
(+ 1)
^
Also works for custom lambdas:
> (define a (lambda (n1 n2) (+ n1 n2 1)))
#<lambda>
> (a 1)
RUNTIME ERROR: Line 1: Expected 2 arguments to lambda, 1 given:
(a 1)
^
It can also do argument type checking for built-in primitives:
> (expt "Hello" 2)
RUNTIME ERROR: Line 1: Incorrect type for 1st argument of 'expt', number expected:
(expt "Hello" 2)
^
Download ↵^
scheme-0.9.tar.bz2 (11947 bytes, MD5: 89f92047eb2fa2962f363c8dac9d2d56)