Append Element To List Property

The list "append" operation works as follows:

  • Find the location of the list in the "Object Store"
  • Get the list from the "Object Store" and append the value from the "Value" stack.
  • Replace the old list with the new appended list in the "Object Store.

More formally,

if the following are true:
  • Expression Stack at time t = [ [ ], [ [ obj.append(x), ys ], rest ] ]
  • Value Stack at time t = [ [ value, [ ] ], [ next_level, other_levels ] ]
  • value at obj in map (Variables Map at time t) = Python reference idx
  • the element at index idx of stack (Python Object Store at time t) = Python list entries

then Python Object Store at time (t + 1) = result of storing (Python list (result of appending value to entries)) at index idx of stack (Python Object Store at time t)

For example, suppose that:
  • Expression Stack at time 10 = [ [ ], [ [ numbers.append(8), [ ] ], [ ] ] ]
  • Value Stack at time 10 = [ [ 8, [ ] ], [ [ ], [ ] ] ]
  • Variables Map at time 10 = [ entry numbers: (Python reference 0), [ ] ]
  • Python Object Store at time 10 = [ [2, 4, 6], [ ] ]

Then we know that:

  • value at numbers in map (Variables Map at time 10) = Python reference 0
  • the element at index 0 of stack (Python Object Store at time 10) = [2, 4, 6]

Then we can conclude:

Python Object Store at time (10 + 1) = result of storing (Python list (result of appending 8 to [ 2, [ 4, [ 6, [ ] ] ] ])) at index 0 of stack (Python Object Store at time 10)

We know that

result of appending 8 to [ 2, [ 4, [ 6, [ ] ] ] ] = [ 2, [ 4, [ 6, [ 8, [ ] ] ] ] ]

And

result of storing [2, 4, 6, 8] at index 0 of stack [ [2, 4, 6], [ ] ] = [ [2, 4, 6, 8], [ ] ]

Therefore, we conclude that

Python Object Store at time (10 + 1) = [ [2, 4, 6, 8], [ ] ]

Which simplifies to:

Python Object Store at time 11 = [ [2, 4, 6, 8], [ ] ]

See the full proof here.

Try stepping through the simulator to see LW Python append 8 to the "numbers" list.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments