You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A map is a definition with only definitions in it, but no statement.
Two scoping operations exist, scope.value and scope value (often conventionally written as scope[value], although the block does not matter. The first one is called scoping and the second one is called indexing or applying. Scoping restricts the lookup while evaluating value to only what is in scope. Indexing injects the scope into the current evaluation context.
For example:
digit_spelling is
0 is "zero"
1 is "one"
2 is "two"
3 is "three"
4 is "four"
5 is "five"
6 is "six"
7 is "seven"
8 is "eight"
9 is "nine"
A is 3
digit_spelling.0 // "zero"
digit_spelling[0] // "zero"
digit_spelling.A // Error: no "A" in scope
digit_spelling[A] // "three"
digit_spelling A // "three", the block is unnecessary in that case
digit_spelling A+3 // "six" - This is a statement, so this parses as digit_spelling(A+3)
(digit_spelling A+3) // Error - This is an expression, so this parses as digit_spelling(A)+3
digit_spelling[A+3] // "six"
(digit_spelling[A+3]) // "six"
The current documentation now defines XL scoping rules in more details. Basically:
scope.value
andscope value
(often conventionally written asscope[value]
, although the block does not matter. The first one is called scoping and the second one is called indexing or applying. Scoping restricts the lookup while evaluatingvalue
to only what is inscope
. Indexing injects the scope into the current evaluation context.For example:
These scoping rules are partially implemented in the interpreter, see for example this test for maps, this test for anonymous maps and this test for the scoping operation. Note that all these tests mistakenly talk about "array", when it should be "map".
They are probably not working at all in the compiler at the moment.
The text was updated successfully, but these errors were encountered: