Functions¶
Types of functions¶
Functions are the building blocks of a task. They are used to define the
behavior of the program. In Radon, we declare functions using the fun
keyword.
It is followed by the name of the function, the parameters, and the return type.
The body of the function is enclosed in curly braces.
In Radon, there are three types of functions:
- Named functions
- Anonymous functions
- One-liner functions
Named functions¶
Anonymous functions¶
One-liner functions¶
one_liner_functions.rn | |
---|---|
Calling functions¶
Calling a function is done by using the function name followed by the arguments in parentheses.
calling_functions.rn | |
---|---|
That's it! You now know how to call functions in Radon.
Function parameters¶
Function parameters are the names listed in the function definition. They are used to pass values into the function. The parameters are separated by commas. The parameters are optional.
We can also leave out the parentheses if there are no parameters.
function_parameters.rn | |
---|---|
Default parameters¶
Default parameters are used to assign a default value to a parameter. If the parameter is not passed, the default value is used.