-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdlib.simplex
More file actions
53 lines (46 loc) · 1.29 KB
/
stdlib.simplex
File metadata and controls
53 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(let <= (lambda x y
(cond (= x y) true
(< x y) true
true false)))
(let >= (lambda x y
(cond (= x y) true
(> x y) true
true false)))
(let append (lambda ls1 ls2
(cond (= nil ls1) ls2
(= nil (car ls1)) ls2
(= nil ls2) ls1
(= nil (car ls2)) ls1
true (cons (car ls1) (append (cdr ls1) ls2)))))
(let len (lambda xs
(cond (= (car xs) nil) 0
(= (cdr xs) nil) 1
true (+ 1 (len (cdr xs))))))
(let map
(lambda fn xs
(cond (= xs nil) nil
true (cons (fn (car xs)) (map fn (cdr xs))))))
(let readLine (lambda
(sequence
(let readLine' (lambda acc
(sequence
(let next (read))
(cond (= next nil) acc
(= next (car endl)) acc
(= (car acc) nil) (readLine' (cons next nil))
(= (cdr acc) nil) (readLine' (list next (car acc)))
true (readLine' (cons next acc))))))
(reverse (readLine' '')))))
(let reverse (lambda xs
(if (<= (len xs) 1)
xs
(append (reverse (cdr xs)) (list (car xs))))))
(let debugPrint
(lambda x
(sequence
(print '
---DEBUG------------------------------------------------------------------------
' (string x) '
---END DEBUG--------------------------------------------------------------------
')
x)))