proposal: desugar all ops (not just %)

29 views
Skip to first unread message

Buck Evan

unread,
May 30, 2023, 1:04:43 PM5/30/23
to Jsonnet
This would allow built-in operations to become valid arguments to the various higher-order functions in `std`. Since there are so many (23), I'd put them in an `std.op` subsection.

* `std.op.add(x, y)` implements `+`
* `std.op.neg(x)` implements unary `-`

This has a side-benefit of making the core language smaller and simpler, with no need for operator precedence. (BTW I don't see how precedence enters into the formal semantics, but I've no practice reading that kind of thing. :)

Prior art in https://docs.python.org/3/library/operator.html

Sebastien Diot

unread,
May 31, 2023, 6:37:13 AM5/31/23
to Jsonnet
I was planing to create a small library for myself, which does that by simply having functions use the operators, but having it built-in would be even better.

Dave Cunningham

unread,
Jun 1, 2023, 8:30:16 AM6/1/23
to Sebastien Diot, Jsonnet
It's not a bad idea to have named versions of the operators.  Essentially it means you can to `std.add` instead of `function(x,y) x + y`, which can be more readable.

You don't need to desugar them to get that, though.  Desugaring means you have both the operator and the standard function, but the operator is implemented in terms of the standard function.  If all you want is to have both the operator and the standard function, it is also possible to implement the standard function in terms of the operator.

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/3b43ab69-2764-437b-abe5-36a4c8a90f1en%40googlegroups.com.

Buck Evan

unread,
Jun 2, 2023, 11:13:26 AM6/2/23
to Dave Cunningham, Sebastien Diot, Jsonnet
Agreed. I just thought it a nice side benefit that the order of operations can be handled in the desugaring, and the core language no longer needs any notion of operator precedence nor "left-binding", just function calls. I don't think those are formally specified at the moment, so it also makes the formal definition more comprehensive.

I completely agree it's not essential though.

You received this message because you are subscribed to a topic in the Google Groups "Jsonnet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsonnet/Qk6ILtk-kxg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/CANarjTiBfHouCeGRgvKx%3DrAMR6Se5w1-W2rhb5Lo6QKHwkDCuQ%40mail.gmail.com.

Buck Evan

unread,
Jun 2, 2023, 11:16:22 AM6/2/23
to Dave Cunningham, Sebastien Diot, Jsonnet
What was the cause for desugaring modulus but not division? In my mind they're nearly identical.

Dave Cunningham

unread,
Jun 13, 2023, 4:33:16 PM6/13/23
to Buck Evan, Sebastien Diot, Jsonnet
Modulus is also used for string formatting (intended to be Python compatible)
Reply all
Reply to author
Forward
0 new messages