github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/doc/tutorial/basics/4_references/80_cycle.txt (about)

     1  cue eval -i -c cycle.cue
     2  cmp stdout expect-stdout-cue
     3  
     4  -- frontmatter.toml --
     5  title = "Reference Cycles"
     6  description = ""
     7  
     8  -- text.md --
     9  CUE can handle many types of cycles just fine.
    10  Because all values are final, a field with a concrete value of, say `200`,
    11  can only be valid if it is that value.
    12  So if it is unified with another expression, we can delay the evaluation of
    13  this until later.
    14  
    15  By postponing that evaluation, we can often break cycles.
    16  This is very useful for template writers that may not know what fields
    17  a user will want to fill out.
    18  
    19  -- cycle.cue --
    20  // CUE knows how to resolve the following:
    21  x: 200
    22  x: y + 100
    23  y: x - 100
    24  
    25  // If a cycle is not broken, CUE will just report it.
    26  a: b + 100
    27  b: a - 100
    28  
    29  -- expect-stdout-cue --
    30  x: 200
    31  y: 100
    32  a: _|_ // cycle detected
    33  b: _|_ // cycle detected