Call a function: Difference between revisions

Content added Content deleted
(→‎{{header|Déjà Vu}}: Fixes example)
(Added zkl)
Line 1,640: Line 1,640:


The shell does not support the use of named parameters. There is no lookahead in the shell, so functions cannot be called until their definition has been run.
The shell does not support the use of named parameters. There is no lookahead in the shell, so functions cannot be called until their definition has been run.

=={{header|zkl}}==
The syntax and semantics of function calls is the always the same: name/object(parameters). All calls are varargs, it is up to the callee to do default/optional parameter handling (but that is hidden from the programmer). No named parameters. Pass by reference or value, depending.

Using f has a function, method or object:
<lang zkl>f(); f(1,2,3,4);
fcn f(a=1){}() // define and call f, which gets a set to 1
fcn{vm.arglist}(1,2,3,4) // arglist is L(1,2,3,4)
fcn{a1:=vm.nthArg(1)}(1,2,3) // a1 == 2
(f() == True); (f() and 1 or 2)
if (f()) println()
f(f) // pass f to itself
s:=f()
fcn{}.isType(self.fcn) //True
fcn{}.len.isType(self.fcn) //False, len is a Method</lang>
Partial application is done with the .fp* methods or the 'wrap keyword
<lang zkl>
fcn(a,b,c).fp(1)() // call function with a always set to 1
fcn(a,b,c).fp1(2,3)() // call function with b & c always set to 2 & 3
fcn(a,b,c,d).fpN(3,5)() // call function with d always set to 5
fcn{vm.arglist}.fpN(3,66)(1,2,3,4,5) //-->L(1,2,3,66,4,5)
fcn{}.fpM("01-",5) // use a mask to select parameters
// 1 is supplied, 0 is get upon call, - is chop arglist
fcn{vm.arglist}.fpM("01-",66)(1,2,3,4) //-->L(1,66)

a:=5; f('wrap(b){a+b}) // 'wrap is syntactic sugar for .fpN
// to create a lexical closure --> f(fcn(b,a){a+b}.fpN(1,a))</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==