cue: fix semantics of field comprehensions
They were previously defined as struct comprehensions,
which is slightly different.
As a result, trim’s behavior changed, as this change makes
it harder to detect whether the source of a field is a
comprehension in evaluated code.
Change-Id: I59ec737bc8cc22cc4bc5909fbc9dc7e7d7c7aa5c
diff --git a/doc/ref/spec.md b/doc/ref/spec.md
index e1d4255..a61736a 100644
--- a/doc/ref/spec.md
+++ b/doc/ref/spec.md
@@ -1847,7 +1847,7 @@
### Comprehensions
-Lists and structs can be constructed using comprehensions.
+Lists and fields can be constructed using comprehensions.
Each define a clause sequence that consists of a sequence of `for`, `if`, and
`let` clauses, nesting from left to right.
@@ -1874,9 +1874,11 @@
List comprehensions specify a single expression that is evaluated and included
in the list for each completed iteration.
-Struct comprehensions specify two expressions, one for the label and one for
-the value, that each get evaluated and included as a field in the struct
-for each completed iteration.
+Field comprehensions specify a field that is included in the struct for each
+completed iteration.
+If the same field is generated more than once, its values are unified.
+The clauses of a field comprehension may not refer to fields generated by
+field comprehensions defined in the same struct.
```
ComprehensionDecl = Field [ "<-" ] Clauses .
@@ -1893,31 +1895,10 @@
a: [1, 2, 3, 4]
b: [ x+1 for x in a if x > 1] // [3, 4, 5]
-c: { ("\(x)"): x + y for x in a if x < 4 let y = 1 }
+c: { "\(x)": x + y for x in a if x < 4 let y = 1 }
d: { "1": 2, "2": 3, "3": 4 }
```
-<!---
-The above examples could be expressed as struct unification as follows:
-
-```
-b: [ ]
-bc: {
- x1: _
- next: {
- x2: true & x1 > 1
- next: {
- x3: x1+1
- }
- }
- result: next.next.x3 | []
-}
-```
-
-Struct comprehensions cannot be expressed as such as there is not equivalent
-in the language to have computed field labels.
---->
-
### String interpolation