|
0 |
-> encoding: UTF-8
|
|
1 |
|
|
2 |
Module `env`
|
|
3 |
============
|
|
4 |
|
|
5 |
-> Functionality "Interpret Robin Program" is implemented by
|
|
6 |
-> shell command "bin/robin %(test-file)"
|
|
7 |
|
|
8 |
-> Tests for functionality "Interpret Robin Program"
|
|
9 |
|
|
10 |
### `unbind` ###
|
|
11 |
|
|
12 |
`unbind` removes the given symbol from the environment and evaluates its
|
|
13 |
second argument in that reduced environment.
|
|
14 |
|
|
15 |
| (robin (0 . 1) (small (0 . 1) env (0 . 1))
|
|
16 |
| (unbind if (if #t (literal x) (literal y))))
|
|
17 |
? robin: uncaught exception: (unbound-identifier . if)
|
|
18 |
|
|
19 |
`unbind` removes all trace of binding from the given symbol; if it has
|
|
20 |
several definitions that are shadowed, none of them will be in effect.
|
|
21 |
|
|
22 |
| (robin (0 . 1) (small (0 . 1) env (0 . 1))
|
|
23 |
| (let ((x 7))
|
|
24 |
| (let ((x 8))
|
|
25 |
| (unbind x
|
|
26 |
| x))))
|
|
27 |
? robin: uncaught exception: (unbound-identifier . x)
|
|
28 |
|
|
29 |
`unbind` could be implemented in Robin.
|
|
30 |
|
|
31 |
| (robin (0 . 1) (small (0 . 1) env (0 . 1))
|
|
32 |
| ((bind del-env
|
|
33 |
| (fun (self name env)
|
|
34 |
| (if (equal? env (literal ()))
|
|
35 |
| env
|
|
36 |
| (if (equal? name (head (head env)))
|
|
37 |
| (self self name (tail env))
|
|
38 |
| (pair (head env) (self self name (tail env))))))
|
|
39 |
| (macro (self args env)
|
|
40 |
| (eval (del-env del-env (head args) env) (head (tail args)))))
|
|
41 |
| if (if #t (literal x) (literal y))))
|
|
42 |
? robin: uncaught exception: (unbound-identifier . if)
|
|
43 |
|
|
44 |
### `sandbox` ###
|
|
45 |
|
|
46 |
`sandbox` takes a list of symbols as its first argument, and evaluates its
|
|
47 |
second argument in an environment where all bindings *except* those for the
|
|
48 |
listed symbols have been unbound.
|
|
49 |
|
|
50 |
| (robin (0 . 1) (small (0 . 1) env (0 . 1))
|
|
51 |
| (sandbox (pair tail)
|
|
52 |
| (tail (pair 8 9))))
|
|
53 |
= 9
|
|
54 |
|
|
55 |
| (robin (0 . 1) (small (0 . 1) env (0 . 1))
|
|
56 |
| (sandbox (pair tail)
|
|
57 |
| (head (pair 8 9))))
|
|
58 |
? robin: uncaught exception: (unbound-identifier . head)
|
|
59 |
|
|
60 |
Could be useful to prevent some bindings from being exported from a module.
|
|
61 |
|
|
62 |
`sandbox` could be implemented in Robin.
|
|
63 |
|
|
64 |
| (robin (0 . 1) (small (0 . 1) env (0 . 1))
|
|
65 |
| ((bind elem
|
|
66 |
| (fun (self x xs)
|
|
67 |
| (if (equal? xs ())
|
|
68 |
| #f
|
|
69 |
| (if (equal? x (head xs))
|
|
70 |
| #t
|
|
71 |
| (self self x (tail xs)))))
|
|
72 |
| (bind keep-env
|
|
73 |
| (fun (self names env)
|
|
74 |
| (if (equal? env ())
|
|
75 |
| env
|
|
76 |
| (if (elem elem (head (head env)) names)
|
|
77 |
| (pair (head env) (self self names (tail env)))
|
|
78 |
| (self self names (tail env)))))
|
|
79 |
| (macro (self args env)
|
|
80 |
| (eval (keep-env keep-env (head args) env) (head (tail args))))))
|
|
81 |
| (pair tail)
|
|
82 |
| (head (pair 8 9))))
|
|
83 |
? robin: uncaught exception: (unbound-identifier . head)
|