diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-09-27 09:14:38 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-09-27 09:14:38 -0700 |
commit | e5f9c6aed046e278f3072fcfe94485ad314d58c2 (patch) | |
tree | 460c8550ae612c5ef566f4a526499fbb2ccf352d /063array.mu | |
parent | 56e00e88789f685493002266773bad25e7740874 (diff) | |
download | mu-e5f9c6aed046e278f3072fcfe94485ad314d58c2.tar.gz |
3419
Diffstat (limited to '063array.mu')
-rw-r--r-- | 063array.mu | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/063array.mu b/063array.mu index c4f732d3..001ff7a4 100644 --- a/063array.mu +++ b/063array.mu @@ -1,8 +1,8 @@ scenario array-from-args [ run [ local-scope - x:&:@:char <- new-array 0, 1, 2 - 10:@:char/raw <- copy *x + x:&:@:num <- new-array 0, 1, 2 + 10:@:num/raw <- copy *x ] memory-should-contain [ 10 <- 3 # array length @@ -12,26 +12,25 @@ scenario array-from-args [ ] ] -# create an array out of a list of scalar args -# hacky; needs to be generic -def new-array -> result:&:@:char [ +# create an array out of a list of args +def new-array -> result:&:@:_elem [ local-scope capacity:num <- copy 0 { # while read curr-value - curr-value:char, exists?:bool <- next-ingredient + curr-value:_elem, exists?:bool <- next-ingredient break-unless exists? capacity <- add capacity, 1 loop } - result <- new character:type, capacity + result <- new _elem:type, capacity rewind-ingredients i:num <- copy 0 { # while read curr-value done?:bool <- greater-or-equal i, capacity break-if done? - curr-value:char, exists?:bool <- next-ingredient + curr-value:_elem, exists?:bool <- next-ingredient assert exists?, [error in rewinding ingredients to new-array] *result <- put-index *result, i, curr-value i <- add i, 1 |