comparison code/ll.lm @ 40:d5ccb66ae98b

Move some basic library code out of dotScanner.lm into separate files now that import:from works
author Michael Pavone <pavone@retrodev.com>
date Sat, 26 Jul 2014 15:29:01 -0700
parents
children
comparison
equal deleted inserted replaced
39:0e1fc2b2832f 40:d5ccb66ae98b
1 #{
2 length <- :lst {
3 len <- []
4 while: { not: (lst isInteger?)} do: {
5 lst <- lst tail
6 len <- len + 1
7 }
8 len
9 }
10
11 reverse <- :lst {
12 new <- []
13 while: { not: (lst isInteger?)} do: {
14 new <- (lst value) | new
15 lst <- lst tail
16 }
17 new
18 }
19
20 split:at <- :lst :pos {
21 first <- []
22 i <- 0
23 while: { i < pos } do: {
24 first <- (lst value) | first
25 lst <- lst tail
26 i <- i + 1
27 }
28 #[(reverse: first) lst]
29 }
30
31 map <- :lst fun {
32 new <- []
33 while: { not: (lst isInteger?) } do: {
34 new <- (fun: (lst value)) | new
35 lst <- lst tail
36 }
37 reverse: new
38 }
39
40 fold:with <- :lst acc :fun {
41 while: { not: (lst isInteger?) } do: {
42 acc <- fun: acc (lst value)
43 lst <- lst tail
44 }
45 acc
46 }
47
48 filter <- :lst pred {
49 new <- []
50 while: { not: (lst isInteger?) } do: {
51 if: (pred: (lst value)) {
52 new <- (lst value) | new
53 } else: {}
54 lst <- lst tail
55 }
56 reverse: new
57 }
58
59 flatten <- :lst {
60 fold: lst [] with: :acc el {
61 fold: el acc with: :iacc iel {
62 iel | iacc
63 }
64 }
65 }
66 }