Turbozen Tiny Lisp Source Code

Download Turbozen Tiny Lisp - A simple lisp interpreter for integrating into Objective-C programs. Xcode 2.4. Apache license.

Other Source Code by David Phillip Oster

Turbozen Tiny Lisp is a very small implementation Lisp designed to interface with Objective C.

There isn't much here, but there is enough to define our old friend, the factorial function:

  (set 'fact '(λ (x) (if (<= x 1) 1 (* x (fact (- x 1))))))

  (fact 6)

720
Example of applying a function to arguments:
((λ (x) (+ x x)) 5)

  (set 'double '(λ (x) (+ x x)))

  (double 5)
10
Because of the way namescoping is implemented, This also works
  (set 'x '(λ (x) (+ x x)))

  (x 5)
10
You can also execute expressions like this:

(progn (set 'a 1) (while (< a 20) (print "-> " a) (set 'a (+ a 1))))
Note that after the while expression, you get an implicit progn.

Atoms have arbitrary properties:

   (setPropertyForKey 'a "hello" "world")
"hello"
   (propertyForKey 'a "world")
"hello"
   (propertyKeys 'a)
("world")
   (removePropertyForKey 'a "world")

   (propertyKeys 'a)
()

The TurboZen TinyLisp Reference Manual.

Error handling is minimal, but if you just need a quick read eval print loop to stick some code into, check it out. Here is the main program, simplified by omitting the autorelease pool management, implementing the top level read eval print loop:


#import "TLLisp.h"


int main (int argc, const char * argv[]) {
  TLInit();
  for (;;) {
    TLID *sexpr = TLRead0();
    if (nil == sexpr){
      break;
    }
    NSMutableString *sOut = [NSMutableString string];
    [[sexpr tlEval] tlPrint:sOut];
    printf("%s\n", [sOut UTF8String]);
  }
  TLShutdown();
	return 0;
}
by David Phillip Oster
Source Code: Inspired by: I got tired of waiting for Tim Burks to release his objective-C lisp language, so I wrote my own. Compared to his, mine is a toy. But because it is a toy, the source code is tiny, and easy to build into something else.

Page last modified October 3, 2007