Ganja VS Prettier

I had run into major problems with prettier reformatting code that is intended for Ganja algebra stuff. I had enabled the pretty print option for an observable, and all the ganja stuff stopped working.

Prettier changes the syntax of the javascript and it boggles the ganja engine.

Result: If you are using Ganja.js, turn off prettier.

3 Likes

thanks for sharing!
would you mind sharing a minimal example that breaks if you format it with prettier?
Iā€™m not super familiar with Ganja.js but it looks interesting and seems like a good fit for notebook-based mathematical exploration.

This notebook shows two cells that were run with/without the prettier setting. It totally screws something up for the Ganja internal parser. Syntactic strichnine.

1 Like

The Ganja syntax notes notebook from tmcw comments on this problem as well:

The same goes for pretty much all JavaScript syntax: the ganja interpretation is different. Arithmetic is overloaded as vector operations, negation is the dual, bit-shifting operators mean a dot product instead.
This has meant ā€“ for me in particular ā€“ that when Iā€™m writing a lot of ganja-related code, I turn off Prettier support in Observable - which is guaranteed to format your JavaScript into equivalent JavaScript, but that formatting may change the meaning of said JavaScript in Ganja.