Mercurial > repos > tabletprog
annotate src/kernel.tp @ 372:e857104bd183
Added reverse method to arrays
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 12 Aug 2015 19:16:41 -0700 |
parents | 96e21f525b78 |
children |
rev | line source |
---|---|
33 | 1 /* |
2 array <- #{ | |
3 new <- { | |
4 length <- 0 | |
5 #{ | |
6 each <- :fun { | |
7 repeat: length :idx { | |
8 fun: idx (get: idx) | |
9 } | |
10 } | |
11 } | |
12 } | |
13 } | |
14 */ | |
15 | |
16 true <- #{ | |
17 if:else <- :self trueblock :elseblock { | |
18 trueblock: | |
19 } | |
20 } | |
21 | |
22 false <- #{ | |
23 if:else <- :self trueblock :elseblock { | |
24 elseblock: | |
25 } | |
26 } | |
27 | |
28 filter <- :arr pred { | |
29 output <- arr slice: 0 0 | |
30 each: arr :idx el { | |
31 if: (pred: el) { | |
32 output push: el | |
33 } else: {} | |
34 } | |
35 output | |
36 } |