-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shorthand for specifying objects with keys and values from current scope #522
Comments
It would help to see the larger context for code like this. This shorthand would encourage choosing names for variables that are likely to match field names, which is an unusal pressure to exert. That is, "Choose your names well and you can avoid some typing," but the field names may be of someone else's choosing, so we're either penalizing abstraction (use of different names) or rewarding adoption (using other peoples' field names for our variable names). It's also an unusal punning technique. As I understand it, today in Jsonnet you can get the names of an object's fields as strings, but you can't convert a string to symbol for variable binding lookup. Hence, I don't think you can implement this transformation yourself in Jsonnet. |
The context in which it comes up the most is complex string formatting:
Indeed, a significant portion of my use-cases for this would equally be served by a ruby-like interpolation syntax where arbitrary expressions can be specified in the format string, though I realise that's a more drastic change. To take a real world example: We use jsonnet to define grafana dashboards for a prometheus query backend. I wanted to create a generic function for defining a graph that takes some histogram metric, and returns a graph showing the 50th, 90th and 99th percentiles. Then my query expression looks like this:
Under my proposal, the last line would become:
This is admittedly only a minor hassle, a small piece of syntactic sugar. I understand if it's deemed not worth the extra complexity and amount of language features to learn. |
re: ruby style intepolation, there was this request #45 which is just as much work now as it was then |
Javascript allows what you're asking for:
|
I find myself having to frequently write things like:
ie. an object that takes some local variable, and includes it under the same name.
I'd like to propose a sugar for this which does
{foo}
->{foo: foo}
.ie. the above example would become
{foo, bar, baz}
.This is similar in spirit to
jq
's syntax for this, where{foo}
->{foo: .foo}
.The text was updated successfully, but these errors were encountered: