TYL PROGRAMMING LANGUAGE
▶ ITERATOR
One of the common things in programming is to go over list of items and do operations for each item.

Iterator signature:
[LIST] [ITEM] ~

Say we have a list of numbers:
numbers 10 6 16 10
A looping by index over them, will look like:
numbers 10 6 16 10
max len numbers
index max ~
num numbers index
print num
^
10
6
16
10
While it works, it would be better to get each item by looping over the items themselves, and that's the iterator:
numbers num ~
The selector statement 'numbers num', is the iterator selector. It gets an existing numbers list, and constructs a local variable num, that will belong to the looping statement, and will hold a copy of an item of numbers, for each iteration.

Printing the numbers:
numbers 10 6 16 10
numbers num ~ print num
10
6
16
10
On first iteration, num gets the first number of numbers, so in the statement 'print num', it prints 10. After that, the iterator will go over the rest of the numbers and will print them.

Modification of the list in an iterator statement is forbidden:
state [ 1 1 0 1 ]
state item ~
 ! uncommenting the next line will raise an error!!!
 !state 0 0
^
Line state 0 0, was commented. If you uncomment it and run the code, you'll get an error.

The proper way to iterate over a list and change it, is to loop by index over it:
state [ 1 1 0 1 ]
max len state
print state
ind max ~
item state ind
item 1 - item
state ind item
^
print state
[ 1, 1, 0, 1 ]
[ 0, 0, 1, 0 ]
Or folding iterator block:
state [ 1 1 0 1 ]
max len state
ind max ~ state ind 1 - state ind
print state
PART 2
PART 4