The return value of an invocation can be used to feed a parameter of another invocation, without the use of any intermediate variables. This can be very handy because we can chain subroutine invocations to perform more useful operations.
Here is an example.
A | B | C | D | explanation |
|
1 | comments | line# |
|
||
2 | pre |
|
|||
3 | 5 | retinfo | x | At this point, we need to invoke the “inner” plusOne so that its return value feeds parameter x of the “outer” plusOne. As a result, only the inner invocation of “plusOne” is replaced by a question mark. The outer invocation of “plusOne” will not be resolved, yet. |
|
4 | 5: print (invoke plusOne (?) → x) | 2 |
|
||
5 | 3 | 5: print (invoke plusOne (3) → x) | As in the previous example, the “return” statement copies and pastes the “retinfo” cell, then replaces the question mark with the return value. |
||
6 | 4 | retinfo | x | Columns C and D are deallocated. | |
7 | 5 | retinfo | x | We are now back to line 5. However, line 5 of the pseudocode is now partially resolved to look like cell C5. We have one more invocation of “plusOne” before knowing what value to print. Columns C and D are reallocated. |
|
8 | 5: print (?) | 3 | Cell C5 specifies “3” to pass to parameter “x”. |
||
9 | 3 | 5: print (4) |
|
||
10 | 4 | retinfo | x |
| |
11 | print 4 | 5 | We are back to line 5 of the pseudocode again. This time we know exactly what to print because the line is now fully resolved, as described by cell C9. As a result, 4 is printed. |
||
12 | post |
|
|||