git @ Cat's Eye Technologies Robin / 7606e20
Very beginnings of a list module. Cat's Eye Technologies 13 years ago
2 changed file(s) with 88 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 -> encoding: UTF-8
1
2 Module `list`
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 ### `empty?` ###
11
12 | (robin (0 . 1) (small (0 . 1)) (list (0 . 1))
13 | (empty? (literal symbol)))
14 = #f
15
16 | (robin (0 . 1) (small (0 . 1)) (list (0 . 1))
17 | (empty? ()))
18 = #t
19
20 ### `list?` ###
21
22 | (robin (0 . 1) (small (0 . 1)) (list (0 . 1))
23 | (list? (literal symbol)))
24 = #f
25
26 | (robin (0 . 1) (small (0 . 1)) (list (0 . 1))
27 | (list? ()))
28 = #t
29
30 | (robin (0 . 1) (small (0 . 1)) (list (0 . 1))
31 | (list? (literal (a b c))))
32 = #t
33
34 | (robin (0 . 1) (small (0 . 1)) (list (0 . 1))
35 | (list? (pair 1 2)))
36 = #f
0 (robin (0 . 1) (small (0 . 1))
1 (let (
2 (empty? (fun (li)
3 (equal? li ())))
4 (list? (fun (li)
5 (bind list?-r (fun (self li)
6 (if (empty? li)
7 #t
8 (if (pair? li)
9 (self self (tail li))
10 #f)))
11 (list?-r list?-r li))))
12 (map (fun (app li)
13 (bind map-r
14 (fun (self app li)
15 (if (empty? li)
16 ()
17 (self self app (pair (app (head li)) (tail li)))))
18 (map-r map-r app li))))
19 (fold (fun (app acc li)
20 (bind fold-r (fun (self app acc li)
21 (if (empty? li)
22 acc
23 (self self app (app (head li) acc) (tail li))))
24 (fold-r fold-r app acc li))))
25 (reverse (fun (li)
26 (fold pair () li)))
27 (filter (fun (pred li)
28 (reverse (fold
29 (fun (x acc) (if (pred x) (pair x acc) acc))
30 () li))))
31 (first (fun (pred li)
32 (bind first-r (fun (self pred li)
33 (if (empty? li)
34 ()
35 (if (pred (head li))
36 (pair (head li) ())
37 (self self pred (tail li))))))
38 (first-r first-r pred li)))
39 )
40 (pair
41 (pair (literal empty?) empty?)
42 (pair
43 (pair (literal list?) list?)
44 (pair
45 (pair (literal map) map)
46 (pair
47 (pair (literal fold) fold)
48 (pair
49 (pair (literal reverse) reverse)
50 ())))))))