Scopes and Visibility
CUE uses lexical scoping, not dynamic
Evaluation (or resolution) of references is lazy, consider
That the “example” field unifies the #example definition and a struct does not place the definition’s fields in the scope of the struct.
Cue will reference a value from the nearest enclosing scope. Some quirks are:
- fields without quotes you can reference as identifiers and with dot notation
- fields with quotes require index notation
- fields defined across scopes require sufficient paths to resolve
An alias defines a local value which is not part of the struct. They can be used for accessing shadowed fields, naming intermediate calculations or expressions, and more. They will not be output.
As we’ve seen, there are a few ways to access nested values.
Hidden Fields and Values
Hidden fields and values are prefixed with underscores. You can reference them in the current package and optionally show them when evaluating. Use quotes if you want a real label that begins with an underscore.
Note, hidden fields are not visible across package boundaries. So you cannot refer to hidden fields in imported packages.
Cue can resolve many cycles, as long as they resolve to a final, concrete value.
Structural cycles and recursion are not allowed in Cue. We can define infinite structures as long as the data is finite.