44 | 44 |
| (robin (0 . 1) (small (0 . 1))
|
45 | 45 |
| (literal (hello world)))
|
46 | 46 |
= (hello world)
|
47 | |
|
48 | |
`literal` could be implemented in Robin.
|
49 | |
|
50 | |
| (robin (0 . 1) (small (0 . 1))
|
51 | |
| ((macro (self args env) (head args)) hello))
|
52 | |
= hello
|
53 | 47 |
|
54 | 48 |
`literal` is basically equivalent to Scheme's `quote`.
|
55 | 49 |
|
|
97 | 91 |
| (b (fun (a) (pair a a))))
|
98 | 92 |
| (b 7)))
|
99 | 93 |
= (7 . 7)
|
100 | |
|
101 | |
Functions can be implemented in Robin, using macros, but the implementation
|
102 | |
is rather onerous, so the details are omitted here.
|
103 | 94 |
|
104 | 95 |
`fun` is basically equivalent to Scheme's `lambda`.
|
105 | 96 |
|
|
138 | 129 |
| (find find (literal ((c . d) (e . f) (a . b))) (literal a))))
|
139 | 130 |
= (a . b)
|
140 | 131 |
|
141 | |
`bind` could be implemented in Robin.
|
142 | |
|
143 | |
| (robin (0 . 1) (small (0 . 1))
|
144 | |
| ((macro (self args env) (eval
|
145 | |
| (pair (pair (head args) (eval env (head (tail args)))) env)
|
146 | |
| (head (tail (tail args)))))
|
147 | |
| x (literal hello) (pair x x)))
|
148 | |
= (hello . hello)
|
149 | |
|
150 | 132 |
`bind` is basically equivalent to Scheme's `let`, but only one
|
151 | 133 |
binding may be given.
|
152 | 134 |
|
|
199 | 181 |
| (robin (0 . 1) (small (0 . 1))
|
200 | 182 |
| (let () (literal hi)))
|
201 | 183 |
= hi
|
202 | |
|
203 | |
`let` could be implemented as a recursive macro in Robin.
|
204 | |
|
205 | |
| (robin (0 . 1) (small (0 . 1))
|
206 | |
| ((macro (self args env)
|
207 | |
| (bind bindings (head args)
|
208 | |
| (if (equal? bindings ())
|
209 | |
| (eval env (head (tail args)))
|
210 | |
| (bind binding (head bindings)
|
211 | |
| (bind name (head binding)
|
212 | |
| (bind value (eval env (head (tail binding)))
|
213 | |
| (bind newenv (pair (pair name value) env)
|
214 | |
| (bind newbindings (tail bindings)
|
215 | |
| (bind newargs (pair newbindings (tail args))
|
216 | |
| (eval newenv (pair self newargs)))))))))))
|
217 | |
| ((a (literal b)) (c #f)) (pair a c)))
|
218 | |
= (b . #f)
|
219 | |
|
220 | |
Bindings internal to the recursive macro don't leak.
|
221 | |
|
222 | |
| (robin (0 . 1) (small (0 . 1))
|
223 | |
| ((macro (self args env)
|
224 | |
| (bind bindings (head args)
|
225 | |
| (if (equal? bindings ())
|
226 | |
| (eval env (head (tail args)))
|
227 | |
| (bind binding (head bindings)
|
228 | |
| (bind name (head binding)
|
229 | |
| (bind value (eval env (head (tail binding)))
|
230 | |
| (bind newenv (pair (pair name value) env)
|
231 | |
| (bind newbindings (tail bindings)
|
232 | |
| (bind newargs (pair newbindings (tail args))
|
233 | |
| (eval newenv (pair self newargs)))))))))))
|
234 | |
| ((a (literal b)) (c #f)) newbindings))
|
235 | |
? robin: uncaught exception: (unbound-identifier . newbindings)
|
236 | 184 |
|
237 | 185 |
`let` is basically equivalent to Scheme's `let*` or Haskell's `let`.
|
238 | 186 |
|