-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.scm
More file actions
139 lines (125 loc) · 4.02 KB
/
setup.scm
File metadata and controls
139 lines (125 loc) · 4.02 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(load "eval.scm")
(define global-env (extend-env '(+ - * / sin cos tan log)
`(,+ ,- ,* ,/ ,sin ,cos ,tan ,log)
the-empty-env))
(define (user-space-procedure? obj)
(or (procedure? obj)
(user-procedure? obj)))
(define-sym! 'procedure? user-space-procedure? global-env)
(define-sym! 'eval (lambda (expression . env)
(if (null? env)
(si-eval expression global-env)
(si-eval expression `,@(env))))
global-env)
(define-sym! 'apply si-apply global-env)
(define-sym! 'macroexpand
(lambda (expression)
(let ((value (si-eval (operator expression) global-env)))
(if (not (macro? value))
(error expression " is not a macro")
(macroexpand value (get-application-args expression)))))
global-env)
(define (indentity-with-user! sym)
(define-sym! sym (eval sym) global-env))
;; full list of scheme primitive see
;; http://www.eecs.berkeley.edu/~bh/ssch27/appendix-funlist.html
(indentity-with-user! '=)
(indentity-with-user! '<)
(indentity-with-user! '<=)
(indentity-with-user! '>)
(indentity-with-user! '>=)
(indentity-with-user! 'abs)
(indentity-with-user! 'append)
(indentity-with-user! 'assoc)
(indentity-with-user! 'boolean?)
(indentity-with-user! 'car)
(indentity-with-user! 'caar)
(indentity-with-user! 'caaar)
(indentity-with-user! 'caadr)
(indentity-with-user! 'cadr)
(indentity-with-user! 'cadar)
(indentity-with-user! 'caddr)
(indentity-with-user! 'cdr)
(indentity-with-user! 'cdar)
(indentity-with-user! 'cdaar)
(indentity-with-user! 'cdadr)
(indentity-with-user! 'cddr)
(indentity-with-user! 'cddar)
(indentity-with-user! 'cdddr)
(indentity-with-user! 'ceiling)
(indentity-with-user! 'cons)
(indentity-with-user! 'display)
(indentity-with-user! 'error)
(indentity-with-user! 'even?)
(indentity-with-user! 'floor)
(indentity-with-user! 'integer?)
(indentity-with-user! 'length)
(indentity-with-user! 'list)
(indentity-with-user! 'list-ref)
(indentity-with-user! 'list?)
(indentity-with-user! 'max)
(indentity-with-user! 'min)
(indentity-with-user! 'member)
(indentity-with-user! 'newline)
(indentity-with-user! 'not)
(indentity-with-user! 'null?)
(indentity-with-user! 'number?)
(indentity-with-user! 'odd?)
(indentity-with-user! 'random)
(indentity-with-user! 'set-car!)
(indentity-with-user! 'set-cdr!)
(indentity-with-user! 'string<)
(indentity-with-user! 'string<=)
(indentity-with-user! 'string<=?)
(indentity-with-user! 'string<>)
(indentity-with-user! 'string<?)
(indentity-with-user! 'string=)
(indentity-with-user! 'string=?)
(indentity-with-user! 'string>)
(indentity-with-user! 'string>=)
(indentity-with-user! 'string>=?)
(indentity-with-user! 'string>?)
(indentity-with-user! 'string?)
(indentity-with-user! 'pair?)
(indentity-with-user! 'print)
(indentity-with-user! 'atom?)
(indentity-with-user! 'eq?)
(indentity-with-user! 'equal?)
;; primitive procedures don't recognize user-procedure, so we have to define our own
(si-eval '(define (for-each pro lst)
(if (null? lst)
'done
(begin
(pro (car lst))
(for-each pro (cdr lst)))))
global-env)
(si-eval '(define (map pro lst)
(define (iter lst acc)
(if (null? lst)
acc
(iter (cdr lst)
(append acc
(list (pro (car lst)))))))
(iter lst '()))
global-env)
(si-eval '(defmacro cond (#!rest conds)
(if (null? conds)
'()
(if (eq? (caar conds) 'else)
`(begin ,@(cdar conds))
`(if ,(caar conds)
(begin ,@(cdar conds))
(cond ,@(cdr conds))))))
global-env)
(si-eval '(defmacro let (args #!rest body)
`((lambda ,(map car args)
,@body)
,@(map cadr args)))
global-env)
(si-eval '(defmacro delay (exp)
`(lambda ()
,exp))
global-env)
(si-eval '(define (force exp)
(exp))
global-env)