Iterating over a list
nthBOT edited this page Sep 20, 2021
·
8 revisions
It is possible to iterate over a list, if we parse an input as a list, made of a first element and a rest element.
# add to list
< add {something} to {this list}
- [this list]:{content}
+ [this list]:[content] [something]
> ok
# show list
< show {this list}
* [this list]:{content}
> content: [content]
# iterate over a list
< iterate over {this list}, do {prefix}
* [this list]:{content}
@ _list_all [content] end
# recursion
< _list_all {first} {rest}
@ [prefix] [first]
@ _list_all [rest]
# say
< say {something}
> [something]
# automate
< go
@ 1 add 1 to num
@ 2 add 2 to num
@ 3 add 3 to num
@ 4 show num
@ 5 iterate over num, do say
Next read: Writing self-modifying code