Inflo macros

Last week, I added support for client-side macros to Inflo. While I had previously reengineered the custom autocomplete widget (used for entering content) in anticipation of additions such as this, I hadn’t really thought about how the macros would actually work. In the end, I was surprised at how simple it was to add, although some of my previous changes were helpful (most notably the parser I had written the day before); it took just under one hundred lines of new/changed code. Also nice is how everything is falls back when a macro hasn’t been defined.

register_macro(
    "stopping time", // Name of the macro
    "stopping time ( <i>velocity</i> , <i>deceleration</i> )", // Autocomplete help
    // The function itself; its parameters come in directly from Inflo and one needn't worry about nodes;
    // they're automatically converted to their values.
    function (v1, decel) {
       /* Assumes velocity in m/s and deceleration is in m/s^2 */
       return (v1 / decel).toString() + " s";
    });

The macros behave exactly like a built-in Inflo function, except they’re all currently prefix notation, don’t support sub-expressions in their arguments, need to be user-loaded when viewing the graph (easy with Creammonkey and Greasemonkey), and, for simplicity, ignore units coming into the macro. Anyone that knows some Javascript can write an Inflo macro!