next up previous
Next: 2.2.3 Programs Up: 2.2 Sentence Structure Previous: 2.2.1 Scheme Sentences

2.2.2 J Sentences

J sentences are sequences of words separated by spaces. Most sentences are limited to one physical line and are read from left to right. The J primitive words are formed from the ASCII character set. Primitive words are represented with a single character or a character followed by a period or colon. For example, > represents larger than, >. larger of and >: increment. Terminology from English grammar is used to describe J. Functions are referred to as verbs, constants as nouns, names assigned to values as pronouns and names assigned to verbs as proverbs. Infix conventions are used which means that dyads (verbs having two nouns or pronouns as inputs) are written between the nouns while monads (verbs having one noun or pronoun as input) are written before the noun. For example:

   2 * 3
6
is verbalized as 2 times 3. Compound sentences may be formed as in:
   2 * 3 + 4
14
which might be verbalized as 2 times, 3 plus 4. With the exception of subordinate clauses enclosed in parentheses, verbs are evaluated in the order from right to left so that the sentences may be read from left to right. The right input to a verb is the value of the entire expression to the right and the left input is the value of the noun immediately to the left of the verb. Most verb symbols have two interpretations (dyad or monad) and the choice between interpretations is determined by the context as illustrated by the sentence:
   4 - - 2
6
which is verbalized as 4 subtract negate 2. Punctuation (parentheses) may be used to modify the order of evaluation as in:
   (2 * 3) + 4
10
which is verbalized as The quantity 2 times 3 plus 4.

In J, verbs may be modified by adverbs or conjunctions to form new verbs which are then applied to inputs. For example, in:

   +/1 2 3 4
10
   */1 2 3 4
24
the first is verbalized as plus insert the list 1 2 3 4 while the second is verbalized as times insert the list 1 2 3 4. In each of these sentences, the adverb insert (spelled "/") modifies the verb (plus or times) producing a new verb which sums or multiplies the elements of the list. Adverbs or conjunctions have precedence over verbs with the left input being the entire verb phrase on the left.


next up previous
Next: 2.2.3 Programs Up: 2.2 Sentence Structure Previous: 2.2.1 Scheme Sentences
2002-09-27