Transform tacit BQN to block form

 
 
 
 

Permalink Show 𝔾 More Parens About

Back

About

Here's a BQN thing I made for converting a tacit function to a block function. Type a tacit function into the box and the page will automatically show both a one-argument and two-argument block form. The standard BQN keymap is supported with backslash prefix.

Only a subset of BQN syntax is allowed. Tokens must be primitives, numbers, characters, strings, identifiers, stranded lists of the aforementioned token types, or parentheses. This means no blocks, no angle-bracket lists, no higher-rank arrays, no nested stranded lists, no namespace field accesses, no system functions, and no define/change/export. The string in the input box must be a function expression.

When possible, the page recursively expands trains, atop, over, constant, before, after, and self/swap, and eliminates identity/left/right functions. Nested blocks are created for non-simple operands to cells, each, table, fold, insert, or scan. Nested blocks are also created for non-simple left operands to rank and depth; the right operand is left untouched (it's usually a number or list anyway). A function expression is "simple" if it is a primitive or identifier. Expansion is not performed if the function to be expanded is the operand to a modifier not mentioned above.

This page is inspired by tacit.help. My handwritten tokenizer and parser are pretty janky and do not conform to the BQN spec, but I give them my official "ehhh, good enough" seal of approval. The parser is based on An Implementation of J. The keyboard and permalink functionality are copied from the BQN repl. The font is BQN386.

Check out these examples.

View the source code here.