From f8e89252c99f0ba045a5e567108d1b60ae83ea3b Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 5 Nov 2020 11:55:16 +0530 Subject: add list primitives --- prelude/primitives.scm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'prelude') diff --git a/prelude/primitives.scm b/prelude/primitives.scm index 96dd1dd..2e5f5d9 100644 --- a/prelude/primitives.scm +++ b/prelude/primitives.scm @@ -1,3 +1,13 @@ +(define-module (prelude/primitives) + #: export (primitive-names + primitive-objs + lift-bool + lift-arithmetic + primitives + bool? + true?)) + +(define (lift-bool expr) (if expr 'true 'false)) (define (true? expr) (eq? expr 'true)) (define (false? expr) (eq? expr 'false)) (define (bool? expr) @@ -24,13 +34,22 @@ (define (not-fn x) (not (true? x))) +(define (lift-arithmetic op) + (lambda vals (lift-bool (apply op vals)))) + (define primitives `((+ . ,+) (- . ,-) (* . ,*) + (< . ,(lift-arithmetic <)) + (> . ,(lift-arithmetic >)) + (<= . ,(lift-arithmetic <=)) + (>= . ,(lift-arithmetic >=)) (&& . ,and-special) (|| . ,or-special) - (/= . ,not-fn))) + (/= . ,not-fn) + (first . ,car) + (rest . ,cdr))) (define (primitive-names) (map car primitives)) (define (primitive-objs) (map cdr primitives)) -- cgit v1.2.3