Other Source Code by David Phillip Oster
Turbozen Tiny Lisp is a very small implementation Lisp designed to interface with Objective C.
(set 'fact '(λ (x) (if (<= x 1) 1 (* x (fact (- x 1)))))) (fact 6) 720Example of applying a function to arguments:
((λ (x) (+ x x)) 5) (set 'double '(λ (x) (+ x x))) (double 5) 10Because of the way namescoping is implemented, This also works
(set 'x '(λ (x) (+ x x))) (x 5) 10You 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
Page last modified October 3, 2007