From c93d192c32c376705d3b0a740c81156a44e63ecb Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 4 Nov 2020 08:53:43 +0530 Subject: add basic evaluator, environment --- prelude/primitives.scm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 prelude/primitives.scm (limited to 'prelude') diff --git a/prelude/primitives.scm b/prelude/primitives.scm new file mode 100644 index 0000000..96dd1dd --- /dev/null +++ b/prelude/primitives.scm @@ -0,0 +1,36 @@ +(define (true? expr) (eq? expr 'true)) +(define (false? expr) (eq? expr 'false)) +(define (bool? expr) + (or (true? expr) + (false? expr))) + +(define (and-special . items) + (if (null? items) + 'false + (let ([first (car items)]) + (cond + [(true? first) (apply and-special (cdr items))] + [(false? first) 'false] + [else (error "AND: unable to evaluate non-boolean form" first)])))) + +(define (or-special . items) + (if (null? items) + 'false + (let ([first (car items)]) + (cond + [(true? first) 'true] + [(false? first) (apply or-special (cdr items))] + [else (error "OR: unable to evaluate non-boolean form" first)])))) + +(define (not-fn x) (not (true? x))) + +(define primitives + `((+ . ,+) + (- . ,-) + (* . ,*) + (&& . ,and-special) + (|| . ,or-special) + (/= . ,not-fn))) + +(define (primitive-names) (map car primitives)) +(define (primitive-objs) (map cdr primitives)) -- cgit v1.2.3