-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpreamble.red
14 lines (14 loc) · 1.11 KB
/
preamble.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(define not (template (x) (if x FALSE TRUE)))
(define symbol? (function (x) (not (list? x))))
(define pair (template (left right) (prepend left right)))
(define second (template (x) (first (rest x))))
(define third (template (x) (first (rest (rest x)))))
(define append (function (x y) (if (empty? x) y (prepend (first x) (append (rest x) y)))))
(define los? (function (x) (if (list? x) (if (empty? x) TRUE (if (symbol? (first x)) (los? (rest x)) FALSE)) FALSE)))
(define plusN (function (n) (function (x) (sum x n))))
(define plus1 (plusN 1))
(define A (function (n m) (if (zero? n) (sum m 1) (if (zero? m) (A (sum n -1) 1) (A (sum n -1) (A n (sum m -1)))))))
(define search (function (pred? list) (if (empty? list) _ (if (list? list) (if (pred? (first list)) (first list) (search pred? (rest list))) list))))
(define find (function (key dict) (rest (search (function (entry) (equal? key (first entry))) dict))))
(define filter (function (pred? list) (if (empty? list) NIL (if (list? list) (if (pred? (first list)) (prepend (first list) (filter pred? (rest list))) (filter pred? (rest list))) list))))
'(Preamble Loaded)