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
Pattern
to action pattern:
    ...

to get value pattern:
    return ...

value pattern means: expression

The declaration line contains the function pattern. Names inside that pattern can be parameters.

to declares an action and implicitly opens its execute: body. An action must return nothing. to get also opens an implicit execute: body, but it must return a value on every reachable path.

means: declares a flex replacement that produces a value. Its expression is required on the same line. Use the full function pattern: form when the declaration needs metadata child sections such as patterns:, before:, or after:.

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

to get value squared:
    return value * value

print 5 squared as a line

In this example, value is a parameter variable. When you write 5 squared, the number 5 is the argument (the real value passed in).

Try yourself

Change squared into doubled. 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.