20,741
edits
Line 132: | Line 132: | ||
=== 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. | 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, as is the terminating semicolon after a func block: | ||
So, semantically, these are all equivalent: | So, semantically, these are all equivalent: | ||
var log_message = func() {}; | |||
var log_message = func() {} | var log_message = func() {} | ||
Line 140: | Line 142: | ||
var log_message = func {return;} | var log_message = func {return;} | ||
var log_message = func {nil;} | var log_message = func {nil;} # the semicolon here is also optional | ||
var log_message = func {}; | var log_message = func {}; |