Pop Element from List Return Property

When LW Python pops an element from a list, it returns the popped element as the "Return Value." More formally,

if the following are true:
  • expression state at time t = "call_function_begin"
  • Value Stack at time t = [ [ a, [ ] ], stack ]
  • the expression at time t = name."pop"(args)
  • 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 Return Value at time (t + 1) = the element at index a of stack entries

For example, if the following are true:
  • expression state at time 26 = "call_function_begin"
  • Value Stack at time 26 = [ [ 2, [ ] ], [ ] ]
  • the expression at time 26 = numbers.pop(2)
  • the element at index 0 of stack (Python Object Store at time 26) = [2, 4, 6, 8, 10]

then Return Value at time (29 + 1) = the element at index 2 of stack [ 2, [ 4, [ 6, [ 8, [ 10, [ ] ] ] ] ] ]

Here, LW Python returns the element at index 2, because that is the element that is being popped.

Try stepping through the simulator to see LW Python pop 6 from "numbers" and return it.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments