Karthik Divi
·2 min read

J Online Compiler

J is a descendant of APL that swaps the special character set for ASCII symbols. Designed by Kenneth Iverson and Roger Hui, it's an array programming language where operations apply to entire arrays by default. What takes a loop in most languages takes a single expression in J.

The learning curve is steep. J code is dense -- a line of J can replace 20 lines of Python. But once you internalize the vocabulary (J calls its operators "verbs"), you start thinking about data transformations differently.

Why run J in the browser?

J has a free interpreter (available at jsoftware.com), but installing it just to try a few expressions is unnecessary friction. An online compiler lets you type J expressions and see results instantly. This is particularly useful because J is a language you learn by experimenting -- reading about it only gets you so far.

Array operations in J

NB. Basic array operations
nums =: 3 1 4 1 5 9 2 6 5 3

echo 'Original: ', ": nums
echo 'Sorted:   ', ": /:~ nums
echo 'Sum:      ', ": +/ nums
echo 'Mean:     ', ": (+/ % #) nums

NB. Tacit (point-free) definition
mean =: +/ % #
stdev =: [: %: mean @: *: @: (- mean)

echo 'Std dev:  ', ": stdev nums

NB. Matrix operations
m =: 2 3 $ 1 2 3 4 5 6
echo 'Matrix:'
echo ": m
echo 'Transpose:'
echo ": |: m

A few things to notice: +/ inserts + between all elements (fold/reduce). # gives the length. % is division. So +/ % # reads as "sum divided by count" -- that's the mean, defined without ever naming the argument. This is called tacit programming, and it's central to how J works.

The $ verb reshapes data -- 2 3 $ 1 2 3 4 5 6 creates a 2x3 matrix. |: transposes it. Everything operates on arrays natively.

J on OneCompiler

OneCompiler's J environment lets you evaluate expressions and see results immediately. For a language this terse, fast feedback is essential -- you'll spend a lot of time trying variations of an expression to understand what each verb does. Having a browser tab ready for that beats any other setup.

Start experimenting: J Online Compiler on OneCompiler