Skip to content

Alias/let syntax interpretation and use #687

Answered by cueckoo
cueckoo asked this question in Q&A
Discussion options

You must be logged in to vote

Original reply by @mpvl in cuelang/cue#687 (comment)

The purpose of the X in X="not an identifier": 4 is that it allows referencing the field. The field has a name that is not a valid identifier, so there would otherwise be no way to directly reference the field. For instance, the foo: X references that field and will evaluate to foo: "not an identifier": 4.

A let introduces a name for an expression that can be reused without it being part of the output.
So, where:

X=a: 4
b: X

would evaluate to

a: 4
b: 4

using a let

let X = 4
b: 4

evaluates to

b: 4

instead.

In general if you see a X = it introduces a new name for the element it precedes, without otherwise changing the meaning of this…

Replies: 1 comment

Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
0 replies
Answer selected by cueckoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant