Call a function: Difference between revisions

Line 1,536:
 
If f is a function and c b a ares objects :
<lang Oforth>c b a f</lang>
will push c then b then a on the stack then call f. Calling f does not describe if f will use 1, 2 or 3 arguments (or none).
 
Oforth adds a notation to describe parameters used by a function. It is only a way to add information about which parameters will be used by f :
<lang Oforth>f(a, b, c)</lang>
 
Intepreter will replace this second syntax by the first one. It is only "sugar"...
 
<lang Oforth>c b a f
c b f(a)
c f(a, b)
f(a, b, c)</lang>
 
are the same call to function f and the interpreter will translate all of them into the first one. Which parameters are really used by f will depend on f implementation.
 
Methods need a receiver (the object on which the method will apply and the object that will pushed on th stack when self is used into the method body).
The receiver must be on the top of the stack before calling the method. If c b a and r are objects and m a method :
<lang Oforth>c b a r m</lang>
will call m with r as its receiver.
It is also possible to use the same notation used by functions :
<lang Oforth>r m(a, b, c)</lang>
 
=={{header|PARI/GP}}==
1,015

edits