Set Attribute Property

LW Python sets an attribute to a value by looking up the object in the "Object Store," adding or updating the object's attribute to the value, then replacing the existing object in the "Object Store" with the new object.

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

then Python Object Store at time (t + 1) = result of storing (Python object: (result of storing value at key: attribute in map: entries)) at index idx of stack (Python Object Store at time t)

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

Here is a table view of the "Object Store" at time 32:
IndexTypeContents
0class instance__class_name__Person

We claim that

value at self in map (Variables Map at time 32) = Python reference 0

We also claim that

the element at index 0 of stack (Python Object Store at time 32) = Python object: [ entry "__class_name__": "Person", [ ] ]

Then we conclude that:

Python Object Store at time (32 + 1) = result of storing (Python object: (result of storing "John" at key: "first_name" in map: [ entry "__class_name__": "Person", [ ] ])) at index 0 of stack (Python Object Store at time 32)

We claim that

result of storing "John" at key: "first_name" in map: [ entry "__class_name__": "Person", [ ] ] = [ entry "__class_name__": "Person", [ entry "first_name": "John", [ ] ] ]

We also claim that

result of storing (Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ ] ] ]) at index 0 of stack [ Python object: [ entry "__class_name__": "Person", [ ] ], [ ] ] = [ Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ ] ] ], [ ] ]

Thus, we conclude that:

Python Object Store at time (32 + 1) = [ Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ ] ] ], [ ] ]

This simplifies to:

Python Object Store at time 33 = [ Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ ] ] ], [ ] ]

See here for the full proof.

Notice that the "Person" object initially does not have any attributes. But LW Python adds the following entry:

first_name:"John"

And then updates the "Object Store" with the new object.

Here is a table view of the "Object Store" at time 33:
IndexTypeContents
0class instance__class_name__Person
first_nameJohn

Try stepping through the simulator to see LW Python update the "Person" object in the "Object Store."

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments