Skip to content

Scope injection and scoping operator #9

Open
@c3d

Description

@c3d

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions