-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathkernel.scm
More file actions
68 lines (50 loc) · 1.33 KB
/
kernel.scm
File metadata and controls
68 lines (50 loc) · 1.33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;; Working out what Shutt's Kernel might be like, from the vague
;; general idea. Unfinished and not compared to his yet.
'($call $define 'define ;XXX quote
($ env (name expr)
($call $define name (env expr))))
(($ _ignore (def)
($call $define def ($ env (name expr)
($call $define name (env expr)))))
define)
(define quote ($ env (x) x))
(define cons ($ env (x xs) ($call $cons (env x) (env xs))))
'(define wrap
(lambda (ff)
(lambda params
($call $apply ff params))))
(define wrap
($ env (ff)
($call ($ _ignore (p) ($call p (env ff)))
($ _ignore (fff)
($ env2 params
($call $apply fff (env2 params)))))))
(define lambda
($ env (params body)
(wrap (env (cons $ (cons '_ignore (cons params (cons body '()))))))))
(define if
($ env (test if-true if-false)
(env ((as-boolean test) if-true if-false))))
(define as-boolean (wrap $as-boolean))
(define zero? (wrap $zero?))
(define * (wrap $*))
(define - (wrap $-))
;; $call
;; $define
;; <environment>
;; $apply XXX needed?
;; $
;; _ignore
;; <pair>
;; <nil>
;; $cons $car $cdr
;; <boolean>
;; $as-boolean
;; <number>
;; $zero? $* $-
; example program
(define factorial
(lambda (n)
(if (zero? n)
1
(* n (factorial (- n 1))))))