-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheval.robin
80 lines (60 loc) · 2.42 KB
/
eval.robin
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
;'<<SPEC'
### `eval` ###
-> Tests for functionality "Evaluate Robin Expression (with Small)"
`eval` evaluates its first argument to obtain an environment, then
evaluates its second argument to obtain an S-expression; it then
evaluates that S-expression in the given environment.
| (eval (env) (literal
| (prepend (literal a)
| (prepend (literal b) ()))))
= (a b)
| (eval () (literal
| (prepend (literal a)
| (prepend (literal b) ()))))
? abort (unbound-identifier prepend)
Something fairly complicated that uses `bind`...?
| (bind bindings (prepend
| (prepend (literal same) (prepend equal? ()))
| (prepend
| (prepend (literal x) (prepend #f ()))
| ()))
| (eval bindings (literal (same x x))))
= #t
If two bindings for the same identifier are supplied in the environment
alist passed to `eval`, the one closer to the front of the alist takes
precedence.
| (bind bindings (prepend
| (prepend (literal foo) (prepend (literal yes) ()))
| (prepend
| (prepend (literal foo) (prepend (literal no) ()))
| ()))
| (eval bindings (literal foo)))
= yes
`eval` will happily use whatever type of value you like as the
environment, however, subsequent evaluation will fail when it
tries to look up things in that environment.
| (eval 103 (literal
| (prepend (literal a)
| (prepend (literal b) ()))))
? abort (unbound-identifier prepend)
Evaluation expects the contents of the list which makes up the
environment to be two-element lists. Any list of some other
format will not work for looking things up.
| (eval (prepend #f ()) (literal
| (prepend (literal a)
| (prepend (literal b) ()))))
? abort (unbound-identifier prepend)
Evaluation expects the head of each sublist in the list which makes up the
environment to be a symbol. Any list of some other
format will not work for looking things up.
| (eval (prepend (prepend 7 (prepend #f ())) ()) (literal
| (prepend (literal a)
| (prepend (literal b) ()))))
? abort (unbound-identifier prepend)
`eval` expects exactly two arguments.
| (eval)
? abort (illegal-arguments ())
| (eval 4 5 6)
? abort (illegal-arguments (4 5 6))
'<<SPEC'
(require eval)