395
edits
Philosopher (talk | contribs) m (→Default values for function arguments: python too!) |
Philosopher (talk | contribs) |
||
Line 135: | Line 135: | ||
== Returning from functions == | == Returning from functions == | ||
In Nasal, functions return implicitly the values of the last expression (e.g. "nil" in empty function bodies), you can also add an explicit "return" statement, for example to leave a function early. In addition, it is possible to return values, too. Whenever a function's signature is empty, because it doesn't take any named arguments, the parentheses are optional | In Nasal, functions return implicitly the values of the last expression (e.g. "nil" in empty function bodies), and you can also add an explicit "return" statement, for example to leave a function early. In addition, it is possible to return values, too. Whenever a function's signature is empty, because it doesn't take any named arguments, the parentheses are optional. The terminating semicolon after a func block is always optional: | ||
So, semantically, these are all equivalent: | So, semantically, these are all equivalent: | ||
Line 144: | Line 144: | ||
var log_message = func() {} | var log_message = func() {} | ||
var log_message = func {return;} | var log_message = func {return;} # the semicolon here is also optional | ||
var log_message = func {nil;} # | var log_message = func {nil;} # and here too, of course | ||
var log_message = func {}; | var log_message = func {}; | ||
var log_message = func return; | var log_message = func return; # look, no braces! the function ends at the semicolon | ||
var log_message = func nil; | var log_message = func nil; | ||
Line 156: | Line 156: | ||
var log_message = func() nil; | var log_message = func() nil; | ||
var log_message = func; | var log_message = func; # emptiness is equivalent to "nil" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
edits