Build Constructor Arguments Property

LW Python begins creating new variables by creating an entry where the key is "self" and the value is the length of 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 Function Variables Map at time (t + 1) = [ entry self: (Python reference (length of stack (Python Object Store at time t))), [ ] ]

The first parameter in a Python constructor is always "self." "self" is the reference to the class object that is returned by the constructor. Since this object is created at the same time "self" is added to the "Variables" map, we know that it must be the last object in the "Object Store." Thus, the reference is simply the length of the "Object Store."

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 Function Variables Map at time (21 + 1) = [ entry self: (Python reference (length of stack (Python Object Store at time 21))), [ ] ]

Try stepping through the simulator to see LW Python add "self":0 to the "Function Variables" map.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments