fcall
Input Stack:
|
⇨ | Output Stack:
|
Function call by variable name. This is equivalent to :get,:call
- it retrieves a stored
program from the variable store and executes it. This provides a convenient shorthand for
calling stored functions without separate get and call operations.
Parameters¶
- key: The variable name containing the program to execute
- ...: Additional stack items that may be consumed by the called program
Behavior¶
The operation performs these steps:
1. Retrieves the value stored under key
from the variable store
2. Executes the retrieved value as a program using :call
semantics
3. The program can consume additional stack items and produce any output
Examples¶
Storing and calling a function:
duplicate,(,:dup, ),:set, a,duplicate,:fcall
Pos | Input | Output |
---|---|---|
0 | duplicate | a |
1 | a | a |
This example:
1. Sets a program (,:dup,)
in variable duplicate
2. Puts a
on the stack
3. Calls the duplicate
function using :fcall
4. The function duplicates a
, resulting in a, a
on the stack
Executing a stored function to square the top stack item:
Before | After |
square,(,:dup, :mul, ),:set, name,sps,:eq, :sum | square,(,:dup, :mul, ),:set, name,sps,:eq, :sum, square,:fcall |
This stores the squaring program (,:dup,:mul,)
in variable square
, then calls it using
:fcall
. The program duplicates the sum result and multiplies the copies together,
effectively squaring the value.