J is a language and its different components or words fall into a number of categories. These categories have many similarities to the parts of speech described in natural languages, so J chooses to leverage those analogies rather than create new terms.

As with natural languages it is not necessary to know or use all the parts of speech or all the words of J to make yourself understood. A lot can be accomplished with only nouns and a handful of verbs.

Noun

In the simplest terms a noun is a "thing". For example both dog and cat in the sentence "The dog bites the cat."

Nouns in J are the objects manipulated by verbs.

   5 # 'b'               NB. Both 'b' and 5 are nouns.
bbbbb

(The verb # (Copy) copies the items of the noun to its right the number of times specified by the noun to its left.)

A noun can be assigned a name, in which case it is equivalent to what other computer languages often refer to as variables.

   city=: 'Toronto'      NB. The name city is assigned to the literal list 'Toronto'
   # city                NB. Tally (count) the number of items in city
7

The noun dates is an array of four dates arranged in three columns (Year, Month and Day) created using the verb $ (Shape):

   dates=: 4 3 $ 2008 12 22 2007 6 15 2010 4 9 1999 11 17
   dates
2008 12 22
2007  6 15
2010  4  9
1999 11 17  

All nouns are arrays (including scalars). All arrays have a noun rank (the number of dimensions it has), a shape (the sizes/lengths of each of its dimensions) and a type (numeric, literal/character, symbol).

These properties of dates can be returned as follows:

  # dates          NB. Tally (the number of items in dates)
4
  $ dates          NB. Shape Of (the length of each dimension - four rows and 3 columns)
4 3
  #$ dates         NB. Rank of noun (the number of dimensions)
2
  datatype dates   NB. Type (could also use the foreign conjunction: 3!:0 dates)
integer

Arrays of elements with heterogeneous type (e.g. a combination of numeric and character) are not possible nor necessary. {describe/link to description of arrays of boxed elements}

Verb

Verbs are "doing words" such as chases in the sentence "The dog chases the cat.".

Verbs in J are usually referred to as functions in other programming languages and mathematics.

A verb can be a simple primitive like * (Times), or a combination of primitives that form a verb like +/ (Sum). More complicated verbs can be defined by the user.

Verbs can have both monadic (takes only a right argument) or dyadic (takes both a left and right argument) forms (Vocabulary/Valence).

Verbs have a Vocabulary/Rank associated with each of their arguments

Adverb

Adverbs describe a verb, generally providing more detail about "How" an action is being performed, for example eagerly in the sentence "The dog eagerly chases the cat".

Adverbs in J combine with the verb or noun immediately to their left to create a new verb. The adverb / (Insert) combines with + (Plus) to form the new verb +/ (Sum), but can also combine with * (Times) to form the new verb */ (Product).

Conjunction

Conjunctions connect or combine two words. For example and in the sentence "The dog chases and catches the cat".

Conjunctions in J combine the verb or noun on their right with the verb or noun on their left to create a new word. For example the adverb &(Bond) can be used to combine the number (a noun) 0.5 with the verb + (Plus) to create a new verb 0.5&+ that we could call "Add one-half".

We could take this a step further and use the conjunction @: (At) to combine <. Floor with our new verb "Add one-half" to create a verb <.@:(0.5&+) we could call "Round to the nearest integer".

Gerund

(Dan's sidebar from Vocabulary/backtick to go here?)

Punctuation

Vocabulary/Parts of Speech (last edited 2010-02-09 07:35:09 by RicSherlock)