Replies: 2 comments 5 replies
-
Original reply by @verdverm in cuelang/cue#847 (comment) Related to #484 and cuelang/cue#69 (comment)
|
Beta Was this translation helpful? Give feedback.
-
Original reply by @eonpatapon in cuelang/cue#847 (comment) For those that don't know what does rec {
foo = 1;
bar = 2;
b = { inherit foo bar; };
} Is just a shorthand for: rec {
foo = 1;
bar = 2;
b = {
foo = foo;
bar = bar;
};
}
nix-instantiate --strict --eval test.nix
{ b = { bar = 2; foo = 1; }; bar = 2; foo = 1; } As scoping rules are not the same than
Using inherit in this case works as there is no self referencing attribute:
Note that the keyword In the context of {
Foo=foo: 1
Bar=bar: 2
b: {
foo: Foo
bar: Bar
}
} |
Beta Was this translation helpful? Give feedback.
-
Originally opened by @nyarly in cuelang/cue#847
I'm finding (and perhaps I'm discovering an anti-pattern) that I've got a lot of structs, often in a "function" style
One thing of note is the pattern of using a explicit string as a struct field name, to prevent CUE seeing it as a identifier and recursively trying to resolve it.
But when there's even a few parameters, it feels stuttery (a la Go style.)
Three other languages that occur to me have recognized this stylistic issue, and addressed it. ECMAScript simply allows bare names in
{ }
to be the equivalent of using the enclosing variable value and the object value. Rust does likewise.Nix, on the other hand, has an
inherit
keyword, that takes a list of identifiers. The advantage of this feature is that inherit can also take a parenthesized identifier as a source of inheriting values, which means that a set (~= a struct) can be built up from other sets very easily.For the above example, an ES/Rust style would look like
Nix style:
Beta Was this translation helpful? Give feedback.
All reactions