-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.robin
39 lines (26 loc) · 1.08 KB
/
delete.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
;'<<SPEC'
-> Tests for functionality "Evaluate Robin Expression (with List)"
`delete` evaluates its first argument to a value of any type, and its
second argument to obtain an alist. A new alist is returned which
contains no pairs whose first element are equal to the given element.
| (delete (literal b) (literal ((a 1) (b 2) (c 3))))
= ((a 1) (c 3))
All pairs with the given element as key are removed.
| (delete (literal b) (literal ((a 1) (b 2) (c 3) (b 4))))
= ((a 1) (c 3))
If there are no pairs with the given element as key, the same alist
is returned unchanged.
| (delete (literal r) (literal ((a 1) (b 2) (c 3))))
= ((a 1) (b 2) (c 3))
The following should be true for any identifier i and alist x.
| (let ((i (literal a))
| (x (literal ((a 5) (b 7)))))
| (lookup i (delete i x)))
= ()
| (delete (literal q) 55)
? abort (expected-list 55)
| (delete (literal q) (literal ((a 7) 99 (q 4))))
? abort (expected-list 99)
'<<SPEC'
(define delete (fun (id alist)
(filter (fun (x) (if (equal? (head x) id) #f #t)) alist)))