Functions
A method that returns a value, and the rules that keep you from forgetting one.
So far every program of yours fits inside start, and the only way to get a result out is to
print it. A method acts; it returns nothing.
This section teaches it to return a value — and lays down the two rules that come with it: a return type binds every path, and a statement that does nothing is refused. It ends with parameters you are allowed to leave out.
In this section
- 5.1Returning a value
An arrow, a return, and a call stops being a mere action to become a value.
- 5.2Every path must return
A method that announces a return type must honour it everywhere, and the three ways to forget a path.
- 5.3Only a call stands alone
A statement that computes a value and throws it away is refused — and that refusal closes the last shape of the = trap.
- 5.4Default values
A parameter that may be left out, and the value it takes when nothing is said.