Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
No edit summary
Line 83: Line 83:
== Returning from functions ==
== Returning from functions ==


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:
In Nasal, functions return implicitly the values of the last expression (e.g. "nil" in empty function bodies, or when using a single return; expression), 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 91: Line 91:


var log_message = func() {}
var log_message = func() {}
var log_message = func;


var log_message = func {return;} # the semicolon here is also optional
var log_message = func {return;} # the semicolon here is also optional
var log_message = func return;


var log_message = func {nil;} # and here too, of course
var log_message = func {nil;} # and here too, of course

Navigation menu