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

Expression

Expressions are airthmetic or logical operations. They can appear inside the conditional statements, or as input to a task, or nested in other expression or function calls.

Expressions are defined into the following categories:

Literal Values

[1, true, "no maybe"]
12.2

Results:

[1, true, "no maybe"]

12.2

Variable

value = [1, true, "no maybe"];
value

Results:

[1, true, "no maybe"]

Variables also have a “check” mode, where it returns true if variable exists, false if it does not.

value = [1, true, "no maybe"];
value?
other_var?

Results:

true

false

If you use variable that does not exist, then it will throw an error. You can use try-catch block to catch that error. This is computationally better than checking if a variable exists. But the checking is useful in case of filtering the node functions (explained later).

value = [1, true, "no maybe"];
try { other_var } catch { value }

Results:

[1, true, "no maybe"]

You can also use varible from node, or network in other context. For example:

value = [1, true, "no maybe"];
network echo(json(value))

Results:

[1, true, "no maybe"]

Special variable types like nodes, inputs, output are available besides env, network and node based on what type of task the expression is on.

You will learn more about this on Cross Context Functions and Variables chapter.

Unary Operator

env !true
- 12.0

Results:

false

-12

Binary Operator

(12 > 34) & true
"x" in "xyz"
12 in [123, true]
"my name is" match "^my.*"

Results:

false

true

false

true

If Else

if(!true) {"if true"} else {"if false"}

Results:

"if false"

Function

value = [1, true, "no maybe"];
get(value, 2)

Results:

"no maybe"

All expressions are not garanteed to return a value. If you are using a function expression and expect a value and it does not return it, it’ll be a runtime error. Similar case for if block without else if condition is false, and so on.

echo("Hello world!") + 12

*Error*:

Hello world!

EmptyValueError  at Line 1 Column 1: the expression resulted in empty value

Special function types like nodes, inputs, output are available besides env, network and node based on what type of task the expression is on.

You will learn more about this on Cross Context Functions and Variables chapter.