Minimal J for Beginners (continued)
The minimal elements of J presented on the page prior to this are enough to allow experimentation with some basic J expressions using numbers and strings but are insufficient to define and run your own program.
So, here are a few more elements of J to allow us to build more complex code.
Basics Examples (paste into J) ": Format (numeric to character) ". Do (character to numeric) 'Sum first ',(":#n),' integers = ',":+/n=. i.10 1+".'1' 3 : 0 Define explicit verb (monad/dyad) 0 : 0 Define multi-line noun
sum1st=: 3 : 0
'Sum first ',(":#n),' integers = ',":+/n=. i.y
multi=: 0 : 0
and so on
These examples strain the limits of the simple table format we've been using so far and they require more explanation than our previous ones, so let's look at them in more detail.
The simple monadic uses of format ( ": ) and do ( ". ) are more-or-less inverses of each other. They aren't exact inverses because do evaluates an expression and returns its result. If the expression is simply the character representation of a number, it returns the number as a numeric noun; in this case, format acts as an inverse as it will convert a number to its character representation.