Class Get Attribute Property

When it is time to get the object's attribute, LW Python looks in the "Values" stack to see where the object is in the "Object Store." Then it looks for the attribute in the object and returns the corresponding value. More formally,

if the following are true:
  • expression state at time t = "call_function_begin"
  • the expression at time t = obj.attr
  • Value Stack at time t = [ [ Python reference index, [ ] ], v_stack ]
  • the element at index index of stack (Python Object Store at time t) = Python object: attributes

then Return Value at time (t + 1) = value at attr in map attributes

For example, suppose the following are true:
  • expression state at time 67 = "call_function_begin"
  • the expression at time 67 = self.age
  • Value Stack at time 67 = [ [ Python reference 0, [ ] ], [ [ ], [ ] ] ]
  • Python Object Store at time 67 = [ Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ], [ ] ]

Here is a table view of the "Object Store:"
IndexTypeContents
0class instance__class_name__Person
first_nameJohn
last_nameSmith
age25

Then we claim that

the element at index 0 of stack (Python Object Store at time 67) = Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ]

Here is a table view of the object at index 0:
AttributeValue
__class_name__Person
first_nameJohn
last_nameSmith
age25

Then we conclude that:

Return Value at time (67 + 1) = value at "age" in map [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ]

We claim that:

value at "age" in map [ entry "__class_name__": "Person", [ entry "first_name": "John", [ entry "last_name": "Smith", [ entry "age": 25, [ ] ] ] ] ] = 25

We conclude that:

Return Value at time (67 + 1) = 25

Which simplifies to:

Return Value at time 68 = 25

See here for the full proof.

The object is in index 0 of the "Object Store" and the "age" in this object is 25. Try stepping through the simulator to see LW Python set the return value.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments