Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Variables

Variables are dynamically typed and can be used to store values, functions, and channels of any type for later reuse. The values of variables can be changed through an assignment operation. The language supports both global and local variables.

Global

Global variables can be used everywhere in the program, and their value can be set at the workflow start. To use a global variable, it needs to be declared in the outermost scope, for example, above the actions block.

Example:

global my_variable = 23;

actions {
    my_variable = my_variable + 2;

    // This raises an error because `global`
    // is not allowed inside any scope.
    global another_var = 3;
}

Local

Local variables can only be used within the scope in which they are declared. A local variable can be declared using the let keyword. They cannot be declared in the outermost scope.

Example:

// This raises an error because `let`
// is not allowed on the global scope.
let var1 = 23;

actions {
    let var2 = 3;

    if true {
        var2 = var2 + 2;

        let var3 = 45;

        var3 = 23;
    } // <- `var3` gets deleted at this `}`

    var2 = 78;

    // This raise an error because `var3`
    // is not declared inside this scope.
    var3 = 56;
} // <- `var2` gets deleted at this `}`