How to define functions

apaj edited this page Sep 3, 2018 · 1 revision

Function definitions start with def.

Function name follows.

Function parameters are given in the form of comma-separated list in parentheses, after the name. Each of the parameters, must be be followed by a colon and a type annotation.

Function result type is defined by the colon and another type annotation, after the parentheses. Following the function's result type is an equals sign and pair of curly braces that contain the body of the function.

In cases when the interpreter or compiler can infer the function result type, it does not have to be specified. However, if, for example, the function is recursive, the result type must be explicitly specified.

If a function consists of just one statement, the curly braces may be left out.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.