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 state at time t = "call_function_begin"
  • Value Stack at time t = [ [ value, [ ] ], stack ]
  • the expression at time t = obj.append(x)
  • 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 state at time 20 = "call_function_begin"
  • Value Stack at time 20 = [ [ 8, [ ] ], [ ] ]
  • the expression at time 20 = numbers.append(8)
  • Variables Map at time 20 = [ entry numbers: (Python reference 0), [ ] ]
  • Python Object Store at time 20 = [ [2, 4, 6], [ ] ]

Then we know that:

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

Then we can conclude:

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

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 (20 + 1) = [ [2, 4, 6, 8], [ ] ]

Since 20 + 1 = 21, we conclude:

Python Object Store at time 21 = [ [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