Stacking verbs

Let's kick things up by introducing "forks." J will automagically form a fork when we combine certain functions.

({. 1 2 3) , ({: 1 2 3)
1 3
({. , {:) 1 2 3
1 3

See that? We were able to extract the 1 2 3 out as a single argument! J interprets the series of verbs {., ,, and {: as a "fork" - it sends our argument to the left and right sides, then takes the results and joins them with ,. We can do this with all kinds of verbs.

Cool, right? This helps us read out our expressions like sentences. For instance, "the sum times the last" can be written as +/ * {:, and our argument is automatically passed to both sides as it needs to be.

Closing notes

I hope this gentle introduction alleviates some of the pain that comes with looking at an expression like {: (({: , +/)^:20) 1 1 for the first time. Once you break it down, it's really not so special.

J challenges what it means for code to be "readable." Terse by nature, it uses compact symbols and clever composition tools to let us write code that flows like a conversation.

There's still so much to learn. J has a ton of great tools for representing matrices, polynomials, tables, and much more. If you find posts like these interesting, be sure to let me know on twitter so we can learn more together.

Feel free to poke around the complete J vocabulary to see what else this great language has to offer. The documentation is just as condensed as the language itself, so proceed with caution (and lots of patience).