J
J was designed in the early 1990s by Kenneth Iverson and Roger Hui as an APL that uses only the ordinary ASCII character set. It keeps APL's array semantics, and adds a vocabulary borrowed from grammar: nouns (data), verbs (functions), adverbs and conjunctions (which modify verbs).
Paradigm: Array-Oriented Programming
What Makes J Special
- ASCII only. Primitives are one or two characters such as
+/,#,i.andp:, typed on any keyboard. - Grammar terms. A verb such as
+acts on nouns. An adverb such as/(insert) modifies a verb into a new verb, so+/is "sum". - Trains and forks. Three verbs in a row form a fork:
+/ % #is (sum) divided by (count). Programs are built without naming arguments. - Rank. Every verb has a rank, the dimension of the cells it works on, and the
"conjunction changes it. This generalizes loops over rows, columns or planes. - Free and powerful. The interpreter is open source, with a large standard library, and includes plotting, databases and a web server.
Example: Average and primes in one line each
avg =: +/ % #
avg 2 4 4 4 5
3.8
primes =: (#~ 1&p:) @ i.
primes 30
2 3 5 7 11 13 17 19 23 29
How It Works
avg =: +/ % #is a fork:+/sums,#counts, and%divides the first result by the second.i. 30creates the numbers 0 to 29.1&p:binds1top:to make an "is it prime?" test that returns 0 or 1 for each.#~copies items of the list by that mask (it is "filter"), and@composes the two steps: firsti.builds the numbers, then the filter runs on them.- Both definitions have no variable names or loops, and the second is a real prime finder built from parts of the language.
History and Where It Is Used
J is used for data exploration, teaching array thinking, code golf and quantitative research, and is bundled with the JHS browser interface and JQt IDE. It is a good bridge between APL's ideas and everyday keyboards. Compare the same examples in APL and BQN.
Learn More
- J Software
- J wiki
- Back to Array-Oriented Programming or the PGP roadmap.