DynLex Sections
Function
Use a function when you want to give a name to a piece of behavior and call it again later.
TL;DR
- A function is a reusable named pattern.
- Plain pattern words used in the body become variables.
- Call the function by writing the same pattern words.
Pattern
function pattern:
execute:
...
The first line contains the function
pattern. Names inside that pattern can be
parameters.
For plain words, DynLex detects parameters by usage. If the function body uses a plain pattern
word, that word becomes a parameter variable.
Example
import lib/std.dl
function square value:
execute:
return value * value
print square 5 as line
In this example, value is a parameter variable. When you write square 5,
the number 5 is the argument
(the real value passed in).
Try yourself
Change square into double. Then return value + value.
Use It When
Use a function when the same idea appears more than once, or when you want a long piece of code
to have a clear name.