diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-27 21:38:09 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-27 21:38:09 -0800 |
commit | fca48e92d4e51eb7e5b1a811b65e5d69fadeb713 (patch) | |
tree | 41bdb3252b20d563670e5db848cedc5c3be689cb /073list.mu | |
parent | 7f193a0e006c44604918b54c853bd49508dbe8fd (diff) | |
download | mu-fca48e92d4e51eb7e5b1a811b65e5d69fadeb713.tar.gz |
2483 - to-text can now handle lists
'append' also implicitly calls 'to-text' unless there's a better variant.
Diffstat (limited to '073list.mu')
-rw-r--r-- | 073list.mu | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/073list.mu b/073list.mu index db840647..f3b25142 100644 --- a/073list.mu +++ b/073list.mu @@ -51,3 +51,53 @@ scenario list-handling [ 4 <- 3 ] ] + +recipe to-text in:address:list:_elem -> result:address:array:character [ + local-scope +#? $print [to text: list], 10/newline + load-ingredients + buf:address:buffer <- new-buffer 80 + buf <- to-buffer in, buf + result <- buffer-to-array buf +] + +recipe to-buffer in:address:list:_elem, buf:address:buffer -> buf:address:buffer [ + local-scope +#? $print [to buffer: list], 10/newline + load-ingredients + { + break-if in + $print [000], 10/newline + buf <- append buf, 48/0 + reply + } + # append in.value to buf + val:_elem <- get *in, value:offset + buf <- append buf, val + # now prepare next + next:address:list:_elem <- rest in + nextn:number <- copy next +#? buf <- append buf, nextn + reply-unless next + space:character <- copy 32/space + buf <- append buf, space:character + s:address:array:character <- new [-> ] + n:number <- length *s + buf <- append buf, s + # and recurse + buf <- to-buffer next, buf +] + +scenario display-list [ + assume-screen 40/width, 10/height + run [ + 1:address:list:number <- push 4, 0 + 1:address:list:number <- push 5, 1:address:list:number + 1:address:list:number <- push 6, 1:address:list:number + 2:address:array:character <- to-text 1:address:list:number + 3:array:character <- copy *2:address:array:character + ] + memory-should-contain [ + 3:array:character <- [6 -> 5 -> 4] + ] +] |