A single J sentence is also a program. For example:
(4 + 5) * (3 - 2) 9The J word "=:" assigns (binds) a name (pronoun) to a value (noun). For example, suppose we have defined the following words:
monad =: 3 define =: :Then the sentence:
square =: monad define 'y. * y.'is an explicit definition for the square function. The pronoun "y." always refers to the input of a monad. Given this definition, then we may write:
square 10 100The J notation provides great expressive power when defining functions through an alternate method called tacit definition. A feature of tacit definition is there is no reference to the inputs of a definition. For example, square could also be defined as:
square =: ^&2Here we are using a conjunction (a verb producing verb) called bond (spelled ``SPMamp;'') which takes a verb input on the left (power function, spelled ``
^
'') and a noun input (2) on the
right and produces a new verb which squares its argument. Square could also be defined
as:
square =: *~Here we use the adverb reflex (spelled ``
~
'') which takes a dyad as its left input and
converts the dyad into a monad by using its input y. as its left and right input for the dyad.
In this case the verb derived from * y. is y. * y. .
Finally, the square function occurs frequently enough in programs so that it is provided as a primitive function in J, (spelled "*:". So we could also write:
square =: *: