Lambda
Self-contained and reusable sub-functions with special behaviour.
Lambdas are special 'sub-fuctions' that can be defined within code and executed when needed.
These are an advanced and complex feature, allowing for more dynamic code to be created.

Runnables

The runnable expression is a basic lambda, creating an executable object that can be passed to other functions and run when needed.
1
set {var} to a new runnable:
2
print "hello"
3
run {var}
Copied!
They can be passed to other functions as parameters or return values.
1
function test_func:
2
trigger:
3
set {var} to make_runnable()
4
run use_runnable({var})
5
​
6
function make_runnable:
7
trigger:
8
return a new runnable:
9
print "hello"
10
​
11
function use_runnable(var):
12
trigger:
13
run {var}
Copied!
The variables used in a runnable are frozen. This means their values will not change once the runnable is created.
1
function example:
2
trigger:
3
set {blob} to 5
4
set {var} to a new runnable: // {blob} is frozen as 5
5
assert {blob} is 5
6
set {blob} to 6 // not changed in the runnable
7
run {var} // no error
Copied!
This allows the runnable to be passed to other functions without error, since the value is already saved.

Suppliers

Suppliers are an alternative to runnables that can return a value, so are more appropriate to use with the result of... expression than the run effect.
Like the runnable, the supplier section creates an executable object that can be passed to other functions.
1
set {supplier} to a new supplier:
2
return 6
3
set {var} to result of {supplier} // returns 6
4
assert {var} is 6
5
print result of a new supplier: // returns "supplied value"
6
return "supplied value"
Copied!
Like runnables, suppliers have their variables frozen, so their values will not change after creation.
1
set {var} to 3
2
set {supplier} to a new supplier: // {var} is frozen at 3
3
assert {var} is 3
4
set {var} to 4
5
return {var}
6
set {var} to 5
7
assert result of {supplier} is 4
8
assert {var} is 5
Copied!
Last modified 3mo ago
Copy link