From faaf99cbe037d42f01228a302b69d7ddcacfe2f5 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 7 Aug 2022 15:50:28 -0700 Subject: Add booleans. --- lib/scheme/base/30-if.csc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/scheme') diff --git a/lib/scheme/base/30-if.csc b/lib/scheme/base/30-if.csc index 6262f5a..36edc16 100644 --- a/lib/scheme/base/30-if.csc +++ b/lib/scheme/base/30-if.csc @@ -1,13 +1,17 @@ (export and + boolean=? + boolean? case-lambda cond if + not or unless when) (import (only (csc builtins) - builtin-if)) + builtin-if + call-builtin)) (begin @@ -100,4 +104,23 @@ . body) args) (cl . rest)))))) - (cl (params body0 ...) ...)))))))) + (cl (params body0 ...) ...))))))) + + + (define (not obj) + (if obj + #f + #t)) + + + (define (boolean? obj) + (call-builtin eq? 2 (call-builtin typeof obj))) + + + (define (boolean=? b1 b2 . bs) + (and (boolean? b1) + (let loop ((bs (cons b2 bs))) + (or (null? bs) + (and (boolean? (car bs)) + (call-builtin eq? b1 (car bs)) + (loop (cdr bs)))))))) -- cgit v1.3.1