git @ Cat's Eye Technologies Robin / c974c16
Improve documentation for `lookup`, `delete`, and `extend`. Chris Pressey 4 years ago
4 changed file(s) with 34 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1616 there are other ways to obtain an operator than applying
1717 a `macro` form (for instance there have always been
1818 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.
1924
2025 For the reference implementation,
2126
11
22 -> Tests for functionality "Evaluate Robin Expression (with List)"
33
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))))
59 = ((a 1) (c 3))
610
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))))
814 = ((a 1) (c 3))
915
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))))
1120 = ((a 1) (b 2) (c 3))
1221
1322 The following should be true for any identifier i and alist x.
1423
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)))
1827 = ()
1928
20 | (delete (literal q) 55)
29 | (delete (literal q) 55)
2130 ? abort (expected-list 55)
2231
23 | (delete (literal q) (literal ((a 7) 99 (q 4))))
32 | (delete (literal q) (literal ((a 7) 99 (q 4))))
2433 ? abort (expected-list 99)
2534
2635 '<<SPEC'
00 ;'<<SPEC'
11
22 -> 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.
38
49 | (extend (literal b) 6 (literal ((a 1) (b 2) (c 3))))
510 = ((b 6) (a 1) (b 2) (c 3))
00 ;'<<SPEC'
11
22 -> 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.
310
411 | (lookup (literal b) (literal ((a 1) (b 2) (c 3))))
512 = (2)