Mercurial > repos > icfp2014
comparison code/mike00.lm @ 20:5a36fda13a47
Added fold:with function
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 25 Jul 2014 22:13:17 -0700 |
parents | 84f595cff062 |
children | 5a27dd6f03cd |
comparison
equal
deleted
inserted
replaced
19:84f595cff062 | 20:5a36fda13a47 |
---|---|
33 while: { not: (lst isInteger?) } do: { | 33 while: { not: (lst isInteger?) } do: { |
34 new <- (fun: (lst value)) | new | 34 new <- (fun: (lst value)) | new |
35 lst <- lst tail | 35 lst <- lst tail |
36 } | 36 } |
37 reverse: new | 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 | |
38 } | 46 } |
39 | 47 |
40 makeTree:size <- :lst :size { | 48 makeTree:size <- :lst :size { |
41 ret <- 0 | 49 ret <- 0 |
42 sub <- 0 | 50 sub <- 0 |
163 print: (get: 8 fromTree: tree) | 171 print: (get: 8 fromTree: tree) |
164 print: (treeMap: tree :el { el + 1 }) | 172 print: (treeMap: tree :el { el + 1 }) |
165 print: (tree: tree set: 0 to: 42) | 173 print: (tree: tree set: 0 to: 42) |
166 print: (tree: tree set: 6 to: 42) | 174 print: (tree: tree set: 6 to: 42) |
167 print: (tree: tree set: 8 to: 42) | 175 print: (tree: tree set: 8 to: 42) |
176 print: (fold: lst 0 with: :acc el { acc + el }) | |
168 } | 177 } |
169 | 178 |
170 } | 179 } |