Structs and lists naturally define scopes in ALT. Additionally, pairs define so-called domain scopes, which are unique to ALT.
The current scope can be reached via the scope reference
^. The tilde symbol has been chosen, as it naturally resembles going ‘up’ one level. By applying
^ multiple times, you can reach higher and higher parent scopes. But be careful not to use a ’naked’ scope reference as this results in a structural and infinite loop.
Here are some examples:
You can also write the above code more succinctly using references. References only exist during parse time where they are bound to the (lexically closest) key that matches the reference. So a reference is syntactic sugar for a scoping reference and an indexing operation:
ALT has a unique scope, called the domain scope. You can use a domain scope reference
@ to refer to a key (the domain), that is closest to a value (the range) in a pair. Similar to a scope reference, higher and higher parent domain scopes can be reached by applying a domain scope reference multiple times.
Domain scopes (when combined with regular scopes) enable mapping functionality over structs, and in turn enable a weak form of (bounded) recursion. Here is an example: