Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope injection and scoping operator #9

Open
c3d opened this issue Feb 7, 2020 · 0 comments
Open

Scope injection and scoping operator #9

c3d opened this issue Feb 7, 2020 · 0 comments

Comments

@c3d
Copy link
Owner

c3d commented Feb 7, 2020

The current documentation now defines XL scoping rules in more details. Basically:

  • 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"

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant