Assign Constructor to Variable Property

After LW Python has finished evaluating the constructor, the return value, which is the reference to the new object, is set to the target in the Variables Map. More formally,

if the following are true:
  • the line at time t = i
  • the tab at time t = j
  • statement at line i, tab j = assign statement with target x and expression (Python constructor with name: class_name and arguments: args)
  • Expression Stack at time t = [ [ ], [ ] ]
  • Value Stack at time t = [ [ value, [ ] ], [ ] ]

then Variables Map at time (t + 1) = result of storing value at key: x in map: (Variables Map at time t)

For example, if the following are true:
  • the line at time 39 = 8
  • the tab at time 39 = 0
  • statement at line 8, tab 0 = p = Person("John", "Smith", 25)
  • Expression Stack at time 39 = [ [ ], [ ] ]
  • Value Stack at time 39 = [ [ Python reference 0, [ ] ], [ ] ]
  • Variables Map at time 39 = [ ]

then Variables Map at time (39 + 1) = result of storing (Python reference 0) at key: p in map: (Variables Map at time 39)

We claim that:

result of storing (Python reference 0) at key: p in map: [ ] = [ entry p: (Python reference 0), [ ] ]

Then we conclude that:

Variables Map at time (39 + 1) = [ entry p: (Python reference 0), [ ] ]

Which simplifies to:

Variables Map at time 40 = [ entry p: (Python reference 0), [ ] ]

See here for the full proof.

Try stepping through the simulator to see LW Python update the Variables Map with the new object

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments