Introduction to the J Programming Language
Introduction to J
A Language for Thinking
J is a programming language designed for mathematical, statistical, and logical analysis of data. Created in the early 1990s by Kenneth E. Iverson and Roger Hui, it's not just a tool for telling a computer what to do. It’s a tool for thinking.
Its core philosophy is conciseness. J allows you to express complex operations on entire arrays of data with very few characters. This is called array-oriented programming. Instead of writing a loop to add 1 to every number in a list, you simply tell J to add 1 to the list itself. It handles the details.
Imagine you're directing a painting crew. You could give them step-by-step instructions: “Dip your roller in the blue paint. Roll it on the top-left corner of the wall. Move down. Roll again.” Or you could just say, “Paint this wall blue.” J is like the second command—it operates on the whole “wall” (your data array) at once.
From APL to ASCII
J’s story begins with another language: APL, which stands for A Programming Language. Also created by Iverson, APL was revolutionary in the 1960s for its powerful array-processing capabilities. But it had a significant barrier to entry. APL used a unique set of symbols, many from Greek letters and mathematics, to represent its operations.
To use APL, you needed a special keyboard with symbols like ⌹ (matrix inverse) and ⍴ (reshape). This made it powerful but also impractical for most computers and programmers.
J was designed to solve this problem. It keeps the powerful, array-oriented philosophy of APL but maps all of its operations to the standard ASCII characters found on any keyboard. This made the language far more accessible. A single character in J, like +, can have multiple meanings depending on how it's used, a concept we'll explore later.
| Concept | APL Symbol | J Notation |
|---|---|---|
| Plus | + | + |
| Divide | ÷ | % |
| Reshape Array | ⍴ | $ |
| Grade Up (Sort) | ⍋ | /: |
| Matrix Inverse | ⌹ | %. |
What Makes J Different
J's design leads to some unique and powerful features. Its syntax is built around a simple grammar of parts of speech.
noun
noun
Data, which in J is always an array. A single number is just an array with one item.
verb
verb
A function or operation that acts on nouns.
J also has adverbs and conjunctions, which are operators that modify verbs. For example, the adverb / modifies a verb to act between the items of an array. So, +/ applies the addition verb between the elements of a list, effectively summing it.
This structure enables a style of programming called tacit programming, or point-free style. You define a process without ever naming the data it acts on. It’s like creating a recipe that says “double, then add five” instead of “take the number, multiply the number by two, then add five to the result.”
For example, here is a tacit verb in J that calculates the average of a list of numbers:
avg =: +/ % #
This breaks down as:
+/Sum the list.#Tally the count of items in the list.%Divide the sum by the count.
Notice we never mention the list itself. We just defined a new verb, avg, by combining other verbs and adverbs. This way of thinking—building complex operations from simple, reusable parts—is central to J.
Let's test your understanding of these core concepts.
What was the primary motivation for creating J as a successor to the APL language?
The J programming style that allows you to define a process without explicitly naming the data it operates on is called:
This unique approach makes J a powerful DSL for working with data. While its sparse syntax can look intimidating, it's built on a consistent and logical foundation.