Skip to content

Instantly share code, notes, and snippets.

@mossprescott
Last active October 22, 2016 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mossprescott/0e9ced68d85a4f2581ead84ad4f0964a to your computer and use it in GitHub Desktop.
Save mossprescott/0e9ced68d85a4f2581ead84ad4f0964a to your computer and use it in GitHub Desktop.
Notes on potential syntax for MapFunc with (mutually) embedded EJson

EJson

Starts with all of JSON, so needs ", {, [, number literals, true, false, null (and :, , in context).

Metadata looks like data @ metadata, and the "extended" types are all encoded with it. E.g. "<z85-encoded string>" @ { "ejson.type": "ejson.binary" }.

MapFunc

MapFunc is all functions of zero, one, two, or three arguments. So probably you can write it with parens as in:

Add(Negate(1), Multiply(2, 3))

Holes

For QScript, we have SrcHole, LeftSide, and RightSide which can probably be shortened to src, left, and right (or perhaps , , and .

Probably this is left pretty flexible in the parser so you could have variables with arbitrary names, as long as they can be parsed as identifiers (possibly with backticks).

Sugar

To improve readability, we probably want "infix" syntax for much of MapFunc, with the usual implications.

Questions:

  1. Stick to ASCII, all in on Unicode, or accept/produce either? As long as this is mainly for output and not so much for input, I lean towards prettier/more Unicode.
  2. Aim for some consistency with SQL²? I vote no! Instead make a strong statement that this is different.
  3. Aim for consistency with Scala? Haskell? Other PL? Mathematica?

Perhaps:

Normal Infix Precedence Comment
Constant(x) x wraps embedded EJson
Now() now
Negate(x) -x prefix
Not(x) not x, !x, ¬x prefix
MakeArray(x) [x] Is this syntactically distinct from an EJson array constant?
ConcatArrays(x, y) x ++ y ?
ConcatArrays(MakeArray(x), MakeArray(y)) [x, y] See MakeArray
Add(x, y) x + y ?
Subtract(x, y) x - y ?
Multiply(x, y) x * y ?
Divide(x, y) x / y ?
Modulo(x, y) x % y ?
Power(x, y) x ^ y ? NB: we don't have Xor or bitwise ops
Eq(x, y) x = y ?
Neq(x, y) x ≠ y ?
Lt(x, y) x < y ?
Lte(x, y) x ≤ y ? Hard to read?
Gt(x, y) x > y ?
Gte(x, y) x ≥ y ? Hard to read?
IfUndefined(x, y) x ?? y ? Better operator/symbol?
And(x, y) x and y, x ∧ y ?
Or(x, y) x or y, x ∨ y ? Reads as "v"?
Within(x, y) x in y, x ∈ y ?
MakeMap(x, y) {x: y} Is this syntactically distinct from an EJson object constant?
ConcatMaps(x, y) ?
ConcatMaps(MakeMap(x, y), MakeMap(z, t)) {x: y, z: t} See MakeMaps
ProjectIndex(x, y) x[y]
ProjectField(x, y) x{y} Ugly.
ProjectField(x, Constant(Str(<identifier>))) x.y ?
Range(x, y) x..y ?
Cond(x, y, z) if ...?
Guard(x, t, y, z) ?

That's about 50% of the constructors, but probably 80% or more of the usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment