|
||||||||||||
|
|
||||||||||||
Functions and methodsA function definition defines a function (or method, inside classes) type. A function is a callable object, containing a list of statements (known as code) executed when the function is called. When entering a function, a stack frame is created where local variables exist. A function can also contain imports statements and inner functions, which have access to stack frames of enclosing functions. In expressions, it is possible to create anonymous inline functions, which are treated exactly as inner functions, except that they are only accessible with a function handle returned by inline function expression.
A function has zero or more parameters, plus an optional collector, indicated by
a symbol after `` Parameters may have a default value, given with an expression that must evaluate to a constant at compile time. If a parameter has a default value, all of the following parameters must also have a default value. This restriction is not indicated in the grammar. If a parameter has a default value, it is called optional; otherwise it is required. During a statically bound function call, it is possibile to use named parameters: parameters are prefixed with a name matching the name at definition. These can be given in any order as long as all required parameters are filled up.
If a function definition has the `` arguments := [ argument ( "," argument )* ] [ ".." symbolcollector ] argument := symbolname [ = exprconstant ] function := ["synchronized"] "function" symbolname "(" arguments ")" "{" ( function | import | statement ) * "}"
See also
| Yield
| Import
| Definition statements
| Classes
| Interfaces
| Modules
| Tags
| <function>
| Grammar
| Generator functions
| Namespaces
|
||||||||||||
|
|
||||||||||||