Create And Store Object Property

"When the function parameter is "self," create a new object with the class name and add this to the "Object Store. More formally,

if the following are true:
  • expression state at time t = "call_build_args"
  • the expression at time t = Python constructor with name: class_name and arguments: args
  • Function Variables Map at time t = [ ]
  • Parameters List at time t = [ self, p_rest ]

then Python Object Store at time (t + 1) = result of appending (Python object: [ entry "__class_name__": class_name, [ ] ]) to (Python Object Store at time t)

When LW Python is adding "self" to the "Function Variables" map, it creates an object and uses it as the "value" for the key "self." For example, if the following are true:

  • expression state at time 21 = "call_build_args"
  • the expression at time 21 = Person("John", "Smith", 25)
  • Function Variables Map at time 21 = [ ]
  • Parameters List at time 21 = [ self, [ first_name, [ last_name, [ age, [ ] ] ] ] ]

then Python Object Store at time (21 + 1) = result of appending (Python object: [ entry "__class_name__": "Person", [ ] ]) to (Python Object Store at time 21)

Try stepping through the simulator to see LW Python create the new "Person" object.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments