-
Notifications
You must be signed in to change notification settings - Fork 171
Support a must() builtin #575
Comments
I vote for |
I like `must`, too.
|
I have been thinking about this issue as well, particularly around how That said, I wonder if the self-referential Pretend that strings.Contains, strings.Count, etc, accepted only explicit parameters (so we could express "receiver is contained by" using the same function in which we currently only express "receiver contains").
Pretend the author of the above intends the first However, since #Foo binds to the receiver, this really means that any matching concrete string must contain fewer than 7 occurrences of itself, which is certainly true, but not very useful to express. If we had a special symbol to refer to the receiver, we'd avoid this hypothetical issue, and potentially reduce reader confusion ("is this an unresolvable circular reference? I thought those were disallowed?"). Using the original example, perhaps we could have a notation for referring to the receiver, such as
Perhaps this is also worth a special symbol, for example
or an explicit form without a magic identifier:
(where x is a local binding for the receiver) |
I was surprised to learn that this is not what alias was used for:
|
@bttk you can't use an alias in the following example:
The use of implicit parameters is missing from the spec, which I've raised as #863 The intention of |
@bttk There is an excellent write up on several related constructs (alias, let, hidden fields) here: #699 (comment) |
Good memory, @verdverm 😄 |
This issue has been migrated to cue-lang/cue#575. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
This has come up various times on Slack, noting here for posterity (and so it can be referenced)
The name
must()
was also thrown into the 🚲 shed.Is your feature request related to a problem? Please describe.
Sometimes it is necessary to declare arbitrary constraints on a field.
Taking one such example from Slack, where we try to define
#Foo
as astring
that must contain a numeric value greater than5
:Describe the solution you'd like
As above.
Describe alternatives you've considered
The current alternative is to declare additional (hidden) definitions that express the constraint:
Contrast the proposed
constrain()
builtin which allows the constraint to be declared on the field itself, which is much clearer for the author, reader and user.Additional context
n/a
The text was updated successfully, but these errors were encountered: