List Get Item Property
This property describes how Python retrieves an element from a list in the "Object Store."
if the following are true:
- expression state at time t = "call_function_begin"
- Value Stack at time t = [ [ a, [ Python reference idx, [ ] ] ], stack ]
- the expression at time t = function call with name: "__getitem__" and arguments: args
- 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
- expression state at time 23 = "call_function_begin"
- Value Stack at time 23 = [ [ 1, [ Python reference 0, [ ] ] ], [ ] ]
- the expression at time 23 =
__getitem__(numbers, 1)
- Python Object Store at time 23 = [
[2, 4, 6]
, [ ] ]
First, we know that:
the element at index 0 of stack (Python Object Store at time 23) = [2, 4, 6]
Then we can conclude that:
Return Value at time (23 + 1) = the element at index 1 of stack [ 2, [ 4, [ 6, [ ] ] ] ]
We also know that:
the element at index 1 of stack [ 2, [ 4, [ 6, [ ] ] ] ] = 4
Thus, we can conclude that:
Return Value at time (23 + 1) = 4
Which simplifies to:
Return Value at time 24 = 4
The value stack tells LW Python that the "numbers" list is stored in index 0. And we can see that there is a list [2, 4, 6] in index 0 of the "Object Store." Then at time 24, the return value is the element at index 1 of the list [2, 4, 6], which is 4.
See the full proof here.
Try stepping through the simulator to see LW Python retrieve the element from the list in the "Object Store."
Current Line | 1 | Current Tab | 0 | Time | 0 |
Comments
Please log in to add comments