tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 8cf97699bed5510150ca87f0dd9667c48c3ae65c
parent a91231b194cabb4295713beda6bd8697a1d65429
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Fri, 19 Apr 2019 17:56:24 -0700

Add if macro as shorthand for cond

Diffstat:
tibs/lib.tsp | 14+++++++++-----
tibs/repl.tsp | 15++++++++-------
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -64,6 +64,9 @@ (define (apply fn args) (eval (cons fn args))) +(define if (macro (condition true false) + (list 'cond (list condition true) (list else false)))) + (define e (exp 1.)) (define (root b p) (pow b (/ 1 p))) (define (sqrt x) (root x 2)) @@ -74,13 +77,14 @@ (define (negative? x) (cond ((< x 0) t) (t ()))) (define (! n) - (cond ((= n 1) 1) - (t (* n (! (- n 1)))))) + (if (= n 1) + 1 + (* n (! (- n 1))))) (define (newline) (print "\n")) (define (disp . x) (apply print x) (newline)) (define (disp-string str) - (cond - ((string? str) (print "\"" str "\"")) - (t (print str))) + (if (string? str) + (print "\"" str "\"") + (print str)) (newline)) diff --git a/tibs/repl.tsp b/tibs/repl.tsp @@ -1,13 +1,14 @@ (define (repl) (print "> ") ((lambda (expr) - (cond ((= expr 'quit) (newline)) - (t (do - ((lambda (ans) - (cond ((not (void? ans)) - (disp-string ans)))) - (eval expr)) - (repl))))) + (if (= expr 'quit) + (void) + (do + ((lambda (ans) + (cond ((not (void? ans)) + (disp-string ans)))) + (eval expr)) + (repl)))) (read))) (repl)