DynLex Sections

Function

Use a function when you want to give a name to a piece of behavior and call it again later.

Pattern
function pattern:
    execute:
        ...

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

Parameters are detected by usage for plain words. If the function body uses a plain pattern word name, DynLex treats that pattern element as a parameter.

Example
import lib/std.dl

function square value:
    execute:
        return value * value

print square 5 as line

In this example, value is a parameter. When you write square 5, the number 5 is the argument.

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.