Scope
A scope is like a dictionary with entries inside, where keys hold values.
Definition
Scopes are defined with curly brackets {}
, like so:
myCoolScope = {
place = 'here'
when = 'now'
}
Scopes store entries in alphabetical order. This becomes evident when you map over a scope.
Access
There are three ways you can directly access entries inside a scope.
Dot syntax
myCoolScope.place # output: 'here'
Get syntax
# assuming prop = 'place'
myCoolScope(prop) # output: 'here'
Either way, if the property is not present, null
is returned. And if the outer scope is not found in scope, an error is raised.
Optional chaining syntax
You can chain the missing outer by using question-dot ?.
operator:
nonExisting?.prop # null
The optional chaining won't raise an error when the outer scope is null
.
Operations
==
equal!=
not equal+
addition (merge effect)-
subtraction (difference effect)&
logical AND|
logical OR
logical AND/OR evaluate empty scopes as
false
, otherwisetrue
Scope addition (merge)
The second operand works as if it were a patch for the first operand:
x = { a = 1, b = 3 }
y = { b = 2 }
x + y # { a = 1, b = 2 }
y + x # { a = 1, b = 3 }
values from second operand replace values from the first operand
Scope subtraction (difference)
The subtraction operation results in removing the elements from the second operand that are also present in the first operand:
x = { a = 1, b = 3 }
y = { a = 1 }
x - y # { b = 3 }
only values that are exactly identical are removed