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 Stack at time t = [ [ ], [ [ obj.attribute = val, ys ], rest ] ]
  • Value Stack at time t = [ [ value, [ Python reference idx, [ ] ] ], [ next_level, other_levels ] ]
  • 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 Stack at time 23 = [ [ ], [ [ self."first_name" = first_name, [ ] ], [ ] ] ]
  • Value Stack at time 23 = [ [ "John", [ Python reference 0, [ ] ] ], [ [ ], [ ] ] ]
  • Python Object Store at time 23 = [ Python object: [ entry "__class_name__": "Person", [ ] ], [ ] ]

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

We claim that

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

Then we conclude that:

Python Object Store at time (23 + 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 23)

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 (23 + 1) = [ Python object: [ entry "__class_name__": "Person", [ entry "first_name": "John", [ ] ] ], [ ] ]

This simplifies to:

Python Object Store at time 24 = [ 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