Proposal - Remove Implicit Argument Sugaring from JSON Logic #28
Replies: 5 comments 18 replies
-
Some Slack Conversations copied over,
I communicated this would be controversial because it leverages this change, to allow Additionally,
|
Beta Was this translation helpful? Give feedback.
-
@dslmeinte This guy has the biggest implications for JSON Logic. The other guys are pretty simple (and thus will probably inspire more feedback from the community 😂) The tl;dr is:
|
Beta Was this translation helpful? Give feedback.
-
Self +1. Current Votes
|
Beta Was this translation helpful? Give feedback.
-
For part A: Implicit sugaring is definitely a 2-edged sword. In my opinion, only explicit sugaring can be made to really work consistently (especially over the course of the evolution of the language), by just adding another concept/construct to express the sugared variant of an already-present concept/construct. In this context, with completely and quite limited syntactic freedom, there's very little room to maneuver to be able to consistently distinguish between a desugared and implicitly-sugared utterance. In other words: eliminate implicit sugaring 👍 For part B: chaining-as-a-default is implicit sugaring. Although it would obviously be powerful to have this, there's that 2-edged sword again. So, I'm hesitant to vote either way. |
Beta Was this translation helpful? Give feedback.
-
@toddbaert If available, I would like your buy-in for this. This is a bit of a strong departure / decision; you had mentioned on Slack that you felt there was value in the chaining concept. This is the proposal that kinda introduces it. |
Beta Was this translation helpful? Give feedback.
-
Background
Historically, JSON Logic has had an implicit sugaring rule that some implementations have elected to ignore, that automatically promotes a non-array argument of an operator to an array argument.
Example:
{ "+": 5 }
would be tweaked to be{ "+": [5] }
This offers a nice convenience to folks implementing custom operators, as it helps improve consistency and ease of development of operators (not needing to explicitly handle
[5]
vs5
).This does, however, introduce limitations into the language.
By eliminating it, we could enable operators to have stricter control over the AST traversal, and enable implicit application of operators, allowing for things like:
{ "+": { "val": "arr" } }
and
{ "max": { "map": [{ "val": "arr" }, { "val": "salary" }] } }
Which otherwise would not be possible.
Proposal
Part A
I'd like to eliminate the implicit sugaring from JSON Logic; meaning that implementations will no longer be required to wrap arguments in an array before passing the input to operators.
Part B
I'd like to define two conventions we may use to define operators going forward:
"
{ op: n } should produce the same result as { op: [n] }
".This convention is fairly straightforward. Most operators will follow this pattern.
Implementations may choose to promote the input to an array for convenience, or explicitly handle each type of input.
{ "+": "5" }
should produce the same result as{ "+": ["5"] }
.Our tests should also cover these scenarios to confirm this is enforced.
We can describe an operator as "chaining".
Operators that chain can receive their input directly from the output of another operator.
For example,
{ "+": { "val": "x" } }
with the data{ "x": [1,2,3] }
will produce a result of6
.This is because
+
will receive[1, 2, 3]
, which is the output of theval
operation.--
In practice, these two concepts will usually be applied at the same time.
Beta Was this translation helpful? Give feedback.
All reactions