summaryrefslogtreecommitdiff
path: root/prelude
diff options
context:
space:
mode:
Diffstat (limited to 'prelude')
-rw-r--r--prelude/primitives.scm36
1 files changed, 36 insertions, 0 deletions
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 @@
1(define (true? expr) (eq? expr 'true))
2(define (false? expr) (eq? expr 'false))
3(define (bool? expr)
4 (or (true? expr)
5 (false? expr)))
6
7(define (and-special . items)
8 (if (null? items)
9 'false
10 (let ([first (car items)])
11 (cond
12 [(true? first) (apply and-special (cdr items))]
13 [(false? first) 'false]
14 [else (error "AND: unable to evaluate non-boolean form" first)]))))
15
16(define (or-special . items)
17 (if (null? items)
18 'false
19 (let ([first (car items)])
20 (cond
21 [(true? first) 'true]
22 [(false? first) (apply or-special (cdr items))]
23 [else (error "OR: unable to evaluate non-boolean form" first)]))))
24
25(define (not-fn x) (not (true? x)))
26
27(define primitives
28 `((+ . ,+)
29 (- . ,-)
30 (* . ,*)
31 (&& . ,and-special)
32 (|| . ,or-special)
33 (/= . ,not-fn)))
34
35(define (primitive-names) (map car primitives))
36(define (primitive-objs) (map cdr primitives))