Assign Expression Result Property

When LW Python is executing an assignment statement, the expression is first evaluated and stored in "Return Value." LW Python then updates the target in the "Variables" map with the "Return Value." 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 (function call with name: name and arguments: args)
  • expression state at time t = "end_expr"

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

For example: if the following are true:
  • the line at time 10 = 0
  • the tab at time 10 = 0
  • statement at line 0, tab 0 = c = __add__(5, 9)
  • expression state at time 10 = "end_expr"
  • Variables Map at time 10 = [ ]
  • Return Value at time 10 = 14

then Variables Map at time (10 + 1) = result of storing (Return Value at time 10) at key: c in map: (Variables Map at time 10)

We claim that:

result of storing 14 at key: c in map: [ ] = [ entry c: 14, [ ] ]

After some Algebra, we conclude that:

Variables Map at time 11 = [ entry c: 14, [ ] ]

See here for the full proof.

Try stepping through the simulator to see variable "c" updated with the sum of 5 and 9

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments