Thanks for exploring this idea. I agree the additional syntax for embedded expressions are cumbersome in this case (since the DSL is already so close to JavaScript).
Our tagged template literals allow arbitrary languages to be embedded in vanilla JavaScript. These literals are interpreted by their tag function after Observable transpiles the cell definition to vanilla JavaScript. It seems like what we want here is a transformation prior to Observable transpiling the cell definition to JavaScript, rather than after. That way, Observable can parse the transformed cell definition and extract the references to build the dataflow graph.
So for example, say you have the following cell definition, and Observable somehow knows to apply a PGA2D transformation:
orthocenter = (B&C<<A)^(C&A<<B)
The transformation would run, converting this into something like:
orthocenter = CC.Wedge(CC.Dot(CC.Vee(C, A), B), CC.Dot(CC.Vee(A, B), C))
This is now (Observable) JavaScript, and can be parsed and executed normally by the Observable runtime.
But there are several challenges to this approach:
-
How do you define and register a transpiler?
-
How do you declare that a cell should be transformed by a given transpiler? (I don’t think we want this operation to be global to the notebook; their either needs to be some sort of pragma or metadata associated with each cell that specifies the transpiler.)
-
How do transpilers inject runtime values, such as the CC
Algebra instance above? Are these injected values reactive?
-
When a cell is transpiled, how does syntax highlighting and autocomplete work? (Possibly these are simply disabled when transpilation is active; otherwise we’d have to define extension mechanisms for these features, too.)
Ideally, the transpiler is defined in a cell, and maybe there’s a tiny bit of syntax to apply it to a cell, like:
PGA2D = (await require("ganja.js"))(2, 0, 1)
orthocenter = PGA2D: (B&C<<A)^(C&A<<B)
Anyway, this isn’t an easy problem, sorry! But enabling extensible transpilation could be a very powerful feature, so we’re going to keep thinking about it.