github cue-lang/cue v0.0.10

latest releases: v0.11.0-rc.1, v0.11.0-alpha.5, v0.11.0-alpha.4...
3 years ago

Language touch ups

New-style Comprehensions

This release is characterized by the redesign of field comprehensions, now struct comprehensions. The old format is still supported, but cue fmt will rewrite it to the new format.

The new format looks like:

for k, v in a {
   "\(k)": v
}

instead of

"\(k)": v for k, v in a

This may seem like a gratuitous change, but it has many advantages:

  • generated structs are syntactically and semantically like embeddings
  • large comprehensions are clearer
  • a single iteration can add multiple fields
  • makes scoping clearer

Removal of block quotes

Because a comprehension may start with if, we can use if false { ... } to disable a large block. This, and various other considerations have led to the decision to remove block quotes from the language.

Block quotes are still supported, but they are no longer generated and cue fmt will translate them.

Quoted identifiers

CUE now allows identifiers to be quoted with back ticks:

`foo-bar`: 2

baz: `foo-bar`

This allows fields with odd names to still be referenced using identifiers. More importantly, the allowed space of identifiers should ideally be limited. For instance, it is a good idea to require them to be in Unicode normal form NFC. Allowing arbitrary strings as identifiers seemed like a bad idea. CUE will soon disallow this. For now, cue fmt rewrites strings used labels is they are referenced by some nodes.

Quotes also have another benefit. A disadvantage of the new style comprehensions is that it is harder and less clear to allow the keywords of comprehensions as field names. Consider for instance:

for x in src: 2

CUE will now only allow one such keyword as a field name, but requires quoting otherwise. A future cue fmt may rewrite this as:

`for` x `in` src: 2

Backwards incompatible changes

The language changes introduced do not break anything, as the old formats are still supported. However, at some point they won't be. So be sure to run cue fmt at some point.

  • The ast.LabelName has been changed to have proper semantics in light of the upcoming changes. The signature has been change to reflect the changes properly and to assure code is properly investigated in light of these changes.
  • Comprehensions now iterate only over non-optional regular fields, as would perhaps be expected.
  • Top-level emit values are printed in eval output
  • Top-level struct embeddings are merged in the API

Changelog

b50aecd cmd/cue: make fmt rewrite deprecated cue
21fa535 cue/ast/astutil: export Resolve functionality
0dcf17b cue/ast/astutil: implement Apply
e4523e2 cue/ast/astutil: pick name based on import path
530467a cue/ast/astutil: support adding imports
24d14c5 cue/ast/astutil: use unlikely name for import
40c76b7 cue/ast: add API for setting a position
f0bcfb9 cue/ast: add API to modify comments
92408e3 cue/ast: add back LabelName
749a667 cue/ast: convenience constructors for common types
fe5f886 cue/ast: first step to new comprehension format.
57d6751 cue/format: expressions.input
9af9a90 cue/format: output new comprehension format
982b194 cue/format: tweaks to support embeddings
71eafc4 cue/parser: parse new comprehension syntax
3c38bfc cue: add test for package name override
4245fb4 cue: for structs, iterate only on non-optional regular fields
835ed58 cue: implement quoted identifiers
da00c8b cue: implementation of new comprehensions
7fc421b cue: remove block comments and slices from the language
1fa0552 cue: tighten API of comprehensions
b36d81a cue: various cleanup
1f5a903 doc/ref: allow embeding to be Expression
d44b092 doc/tutorial/basics: some minor fixes
48f82f1 doc/tutorial/basics: update w.r.t. spec.
15aeace pkg/list: add Haskell-style Take and Drop
1ffb95f pkg/list: adding slice function

Don't miss a new cue release

NewReleases is sending notifications on new releases.