Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
Line 180: Line 180:


Declared arguments are checked and defaulted as would be expected: it's an error if you fail to pass a value for an undefaulted argument, missing default arguments get assigned as usual, and any rest parameter (e.g. "func(a,b=2,rest...){}") will be assigned with an empty vector.
Declared arguments are checked and defaulted as would be expected: it's an error if you fail to pass a value for an undefaulted argument, missing default arguments get assigned as usual, and any rest parameter (e.g. "func(a,b=2,rest...){}") will be assigned with an empty vector.
== Specifying parameters at call-time ==
The previously discussed syntax also makes it possible to have functions without any named function arguments in their signature, while specifying arguments only during invocation:
<syntaxhighlight lang="php">
var print_pos = func {
print('lat:',lat, ' lon:', lon, '\n');
}
print_pos( lat:43.94, lon: 23.88);
</syntaxhighlight>
Note how the function's signature doesn't have any named parameters at all - instead, the function call sets up a hash that is added to the namespace during invocation.


===Nested functions, implicit return ===
===Nested functions, implicit return ===

Navigation menu