Pop For Loop Iterable Property

LW Python pops the first element from the iterable (and sets it to the target) before entering the "for" body. More formally,

if the following are true:
  • the line at time t = i
  • the tab at time t = j
  • statement at line i, tab j = for target in iterable_ex:
  • value at j in map (Control Map at time t) = trio ("for", i, [ elem, rest ])

then Control Map at time (t + 1) = result of storing (trio ("for", i, rest)) at key: j in map: (Control Map at time t)

For example, if the following are true:
  • the line at time 17 = 2
  • the tab at time 17 = 0
  • statement at line 2, tab 0 = for value in numbers:
  • value at 0 in map (Control Map at time 17) = trio ("for", 2, [ 1, [ 2, [ 3, [ ] ] ] ])

then Control Map at time (17 + 1) = result of storing (trio ("for", 2, [ 2, [ 3, [ ] ] ])) at key: 0 in map: (Control Map at time 17)

Notice how the entry value changed from

trio ("for", 2, [ 1, [ 2, [ 3, [ ] ] ] ])

to

trio ("for", 2, [ 2, [ 3, [ ] ] ])

The first value in the iterable (1) is popped. Try stepping through the simulator to see this in action.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments