Set For Loop Iterable Property

After the "for" statement iterable has finished evaluating, we save the result to the "control" map.

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:
  • expression state at time t = "end_expr"
  • Return Value at time t = Python reference index
  • the element at index index of stack (Python Object Store at time t) = Python list elements

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

LW Python saves the iterable in the "control" map so that it can go through each element in the "for" loop body. For example, if the following are true:

  • the line at time 16 = 2
  • the tab at time 16 = 0
  • statement at line 2, tab 0 = for value in numbers:
  • expression state at time 16 = "end_expr"
  • Return Value at time 16 = Python reference 0
  • Control Map at time 16 = [ ]
  • the element at index 0 of stack (Python Object Store at time 16) = [1, 2, 3]

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

We claim that:

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

Then we conclude that:

Control Map at time (16 + 1) = [ entry 0: (trio ("for", 2, [ 1, [ 2, [ 3, [ ] ] ] ])), [ ] ]

Which simplifies to:

Control Map at time 17 = [ entry 0: (trio ("for", 2, [ 1, [ 2, [ 3, [ ] ] ] ])), [ ] ]

See the full proof here.

Try stepping through the simulator to see LW Python update the "Control" map.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments