Get Dictionary Item Property

After LW Python evaluates the dictionary name to some reference and the key, LW Python looks up the dictionary object in the Object Store and retrieves the value for the evaluated key. This value is set to the return value. More formally,

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 dictionary entries

then Return Value at time (t + 1) = value at a in map entries

The Values stack does not contain the dictionary object. Instead, it contains a reference, which is the location of the dictionary object in the Object Store. LW Python uses this location to retrieve the dictionary from the Object Store. Then LW Python will look for an entry with the specified key and return the entry value.

For example, if the following are true:

  • expression state at time 36 = "call_function_begin"
  • Value Stack at time 36 = [ [ "ES", [ Python reference 0, [ ] ] ], [ ] ]
  • the expression at time 36 = __getitem__(locations, "ES")
  • the element at index 0 of stack (Python Object Store at time 36) = {"ES": "Spain", "MX": "Mexico"}

then Return Value at time (36 + 1) = value at "ES" in map [ entry "ES": "Spain", [ entry "MX": "Mexico", [ ] ] ]

We claim that:

value at "ES" in map [ entry "ES": "Spain", [ entry "MX": "Mexico", [ ] ] ] = "Spain"

Thus we conclude that:

Return Value at time (36 + 1) = "Spain"

Which simplifies to:

Return Value at time 37 = "Spain"

See here for the full proof.

Try stepping through the simulator to see LW Python set the "Return Value" to the entry value for the key "ES".

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments