Improve documentation for `lookup`, `delete`, and `extend`.
Chris Pressey
4 years ago
16 | 16 |
there are other ways to obtain an operator than applying
|
17 | 17 |
a `macro` form (for instance there have always been
|
18 | 18 |
intrinsic operators; it's not fair to call them "macros".)
|
|
19 |
* The Robin definition of `bind` now checks that the name
|
|
20 |
being bound is a symbol. The Robin definition of `let`
|
|
21 |
is now based on that of `bind` so it inherits this behaviour.
|
|
22 |
* The documentation for the alist functions in the standard
|
|
23 |
library was improved.
|
19 | 24 |
|
20 | 25 |
For the reference implementation,
|
21 | 26 |
|
1 | 1 |
|
2 | 2 |
-> Tests for functionality "Evaluate Robin Expression (with List)"
|
3 | 3 |
|
4 | |
| (delete (literal b) (literal ((a 1) (b 2) (c 3))))
|
|
4 |
`delete` evaluates its first argument to a value of any type, and its
|
|
5 |
second argument to obtain an alist. A new alist is returned which
|
|
6 |
contains no pairs whose first element are equal to the given element.
|
|
7 |
|
|
8 |
| (delete (literal b) (literal ((a 1) (b 2) (c 3))))
|
5 | 9 |
= ((a 1) (c 3))
|
6 | 10 |
|
7 | |
| (delete (literal b) (literal ((a 1) (b 2) (c 3) (b 4))))
|
|
11 |
All pairs with the given element as key are removed.
|
|
12 |
|
|
13 |
| (delete (literal b) (literal ((a 1) (b 2) (c 3) (b 4))))
|
8 | 14 |
= ((a 1) (c 3))
|
9 | 15 |
|
10 | |
| (delete (literal r) (literal ((a 1) (b 2) (c 3))))
|
|
16 |
If there are no pairs with the given element as key, the same alist
|
|
17 |
is returned unchanged.
|
|
18 |
|
|
19 |
| (delete (literal r) (literal ((a 1) (b 2) (c 3))))
|
11 | 20 |
= ((a 1) (b 2) (c 3))
|
12 | 21 |
|
13 | 22 |
The following should be true for any identifier i and alist x.
|
14 | 23 |
|
15 | |
| (let ((i (literal a))
|
16 | |
| (x (literal ((a 5) (b 7)))))
|
17 | |
| (lookup i (delete i x)))
|
|
24 |
| (let ((i (literal a))
|
|
25 |
| (x (literal ((a 5) (b 7)))))
|
|
26 |
| (lookup i (delete i x)))
|
18 | 27 |
= ()
|
19 | 28 |
|
20 | |
| (delete (literal q) 55)
|
|
29 |
| (delete (literal q) 55)
|
21 | 30 |
? abort (expected-list 55)
|
22 | 31 |
|
23 | |
| (delete (literal q) (literal ((a 7) 99 (q 4))))
|
|
32 |
| (delete (literal q) (literal ((a 7) 99 (q 4))))
|
24 | 33 |
? abort (expected-list 99)
|
25 | 34 |
|
26 | 35 |
'<<SPEC'
|
0 | 0 |
;'<<SPEC'
|
1 | 1 |
|
2 | 2 |
-> Tests for functionality "Evaluate Robin Expression (with List)"
|
|
3 |
|
|
4 |
`extend` evaluates its first two arguments to values of any type, and its
|
|
5 |
third argument to obtain an alist. It returns a new alist which
|
|
6 |
associates the first two values in a new pair. The new pair shadows
|
|
7 |
any existing pairs with the same key that may already be in the alist.
|
3 | 8 |
|
4 | 9 |
| (extend (literal b) 6 (literal ((a 1) (b 2) (c 3))))
|
5 | 10 |
= ((b 6) (a 1) (b 2) (c 3))
|
0 | 0 |
;'<<SPEC'
|
1 | 1 |
|
2 | 2 |
-> Tests for functionality "Evaluate Robin Expression (with List)"
|
|
3 |
|
|
4 |
`lookup` evaluates its first argument to a value of any type, and its
|
|
5 |
second argument to obtain an alist. It then searches through the
|
|
6 |
pairs of the alist, looking for the first pair whose first element
|
|
7 |
is equal to the value. If such a pair is found, it returns a
|
|
8 |
one-element list containing the second element of that pair. If no
|
|
9 |
such pair is found, the empty list is returned.
|
3 | 10 |
|
4 | 11 |
| (lookup (literal b) (literal ((a 1) (b 2) (c 3))))
|
5 | 12 |
= (2)
|