tisp

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

commit ae0f563a76640e35760ab51ea839ceae392e6ef9
parent ff7d38834fdbe9dd5e2d09111c0c7e5dc191f1bb
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Tue,  7 May 2019 18:32:42 -0700

Add logical and, nand, or, nor functions

Diffstat:
tibs/lib.tsp | 17+++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -73,9 +73,22 @@ (macro (vars body) (cons (list 'lambda (map car vars) body) (map cadr vars)))) +;;; Logic (define (not x) - (cond (x ()) (t t))) -(define (list . rest) rest) + (if x () t)) +(define and ; Use a macro so arguments aren't evaluated all at once + (macro (a b) + (list 'if a (list 'if b t ()) ()))) +(define nand + (macro (a b) + (list 'not (list 'and a b)))) +(define (or a b) ; De Morgan's theorem + (nand (not a) (not b))) +(define (nor a b) + (and (not a) (not b))) + +;;; Lists +(define (list . lst) lst) (define (apply fn args) (eval (cons fn args)))