Mercurial > repos > icfp2014
comparison code/mike00.lm @ 21:5a27dd6f03cd
Added filter function
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 25 Jul 2014 22:17:47 -0700 |
parents | 5a36fda13a47 |
children | edc89d9c9e10 |
comparison
equal
deleted
inserted
replaced
20:5a36fda13a47 | 21:5a27dd6f03cd |
---|---|
41 while: { not: (lst isInteger?) } do: { | 41 while: { not: (lst isInteger?) } do: { |
42 acc <- fun: acc (lst value) | 42 acc <- fun: acc (lst value) |
43 lst <- lst tail | 43 lst <- lst tail |
44 } | 44 } |
45 acc | 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 | |
46 } | 57 } |
47 | 58 |
48 makeTree:size <- :lst :size { | 59 makeTree:size <- :lst :size { |
49 ret <- 0 | 60 ret <- 0 |
50 sub <- 0 | 61 sub <- 0 |
172 print: (treeMap: tree :el { el + 1 }) | 183 print: (treeMap: tree :el { el + 1 }) |
173 print: (tree: tree set: 0 to: 42) | 184 print: (tree: tree set: 0 to: 42) |
174 print: (tree: tree set: 6 to: 42) | 185 print: (tree: tree set: 6 to: 42) |
175 print: (tree: tree set: 8 to: 42) | 186 print: (tree: tree set: 8 to: 42) |
176 print: (fold: lst 0 with: :acc el { acc + el }) | 187 print: (fold: lst 0 with: :acc el { acc + el }) |
188 print: (filter: lst :el { el > 4 }) | |
177 } | 189 } |
178 | 190 |
179 } | 191 } |