Call Add Function Property

When the state is "call_function_begin" and the expression is an addition, then update the return value to the sum of the two values in the value stack. More formally:

if the following are true:

  • expression state at time t = "call_function_begin"
  • Value Stack at time t = [ [ a, [ b, [ ] ] ], stack ]
  • the expression at time t = function call with name: "__add__" and arguments: args

then Return Value at time (t + 1) = b + a

For example,

if the following are true:

  • expression state at time 9 = "call_function_begin"
  • Value Stack at time 9 = [ [ 2, [ 5, [ ] ] ], [ ] ]
  • the expression at time 9 = __add__(5, 2)

then Return Value at time (9 + 1) = 5 + 2

Notice how the values ([2, [5, []]]) are reversed before they are added. The "Values" stack prepends values, which results in a reverse order. Reversing the values again just before adding them changes the list back to the original order.

The conclusion can be simplified to:

Return Value at time 10 = 7

Try stepping through the simulator to see the "Return Value" set to 7.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments