Nouns hold data. Examples are 1, 3 4 5, and 'abc'.
Nouns have type and precision, shape, and elements.
Types and PrecisionsData in J come in types that indicate the general sort of data; each type comprises precisions that describe the data in more detail. All the atoms in a noun must be of the same precision. Data within the same type can be joined together into arrays, and J will make reasonable conversions between precisions to choose a suitable precision for the entire noun.
The operations allowed on a noun depend on its type. All nouns can participate in nonnumeric operations, such as copying, joining into an array, and comparison for equality. Only numeric types can participate in numeric operations such as addition and multiplication, and only character nouns with byte precision may be written or read from files.
Atoms and ArraysA noun is either an atom or an array.
The smallest unit of data is the atom (from Greek a not + temnein to cut, i. e. something that cannot be divided). A numeric atom is a number; a character atom is a letter. The box is a special kind of atom, discussed below. Scalar is another word for atom.
An array is a single noun that contains multiple atoms organized along axes. Any number of axes is allowed. An array with one axis is called a list, one with 2 axes a table, and one with 3 axes a brick.
i. 3 NB. a list 0 1 2 i. 2 3 NB. A table 0 1 2 3 4 5 i. 2 3 4 NB. A brick 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Arrays must be homogeneous:
Boxing is a way to bypass the requirement for homogeneous arrays. Boxing a noun produces an atom, called a box, whose contents are the value of the noun. The box can be put into an array with other boxes.
A box is not a numeric type, even if its contents are numeric, so the box cannot participate in numeric operations.
'abc',1 2 3 NB. Heterogeneous array not allowed |domain error | 'abc' ,1 2 3 (<'abc') NB. Put the string into a box +---+ |abc| +---+ (<'abc'),(<1 2 3) NB. OK to join two boxes +---+-----+ |abc|1 2 3| +---+-----+
A box may be opened, which creates a noun containing the contents of the box.
ConstantsConstants are words that directly represent nouns. They include numbers, byte strings between single quotes, and the primitive nouns a. (the list of all 256 bytes) and a: (a box containing 0$0).
A constant containing a single number or letter, e. g. 5, 1j2, and 'c', represents an atom. A constant containing more than one number or letter, e. g. 1 3 and 'abc', represents a list.
There is no way to write a constant representing a single-element list. Such values must be constructed by reshaping to length 1.
Shape and RankThe shape of a noun is a list giving the number of atoms along each axis. Since an atom has no axes, its shape is an empty list.
The number of axes, which is the same as the number of atoms in the shape, is called the rank of a noun.
i. 4 NB. shape is 4 0 1 2 3 i. 2 3 NB. shape is 2 3, i. e. 2 rows, 3 columns 0 1 2 3 4 5
The sentence $ y gives the shape of y. The sentence # $ y gives the rank of y.
Indexes and Arrays Of ArraysA list is a series of atoms. The atoms are distinguished by a sequential number, called the index, that starts at 0 for the first atom. (Zero-orgin indexing points to the start of an interval, whereas the ordinary, ordinal, terminology may name it as a whole, and points to the cardinal value at its end.)
A table can be thought of as a series of lists (all of the same length), where the lists are distinguished by a index.
Likewise, a brick can be thought of as a series of tables distinguished by an index, and so on for arrays of any rank.
The index list of an atom of an array is a list, whose length is the rank of the array, which gives the coordinates of the atom in the array. The first number in the index selects a component along the first axis; within that component, the second number in the index selects a component; and so on, specifying an atom uniquely.
CellsThe indexing process described above can be stopped before it specifies an atom. For example, given a table, we could have a partial index list 0 which would specify the first list in the table without going on to select an atom from that list.
Such an incomplete index is called a subindex, and the noun specified by the subindex is called a cell.
i. 2 3 0 1 2 3 4 5 NB. subindex of 0 designates the cell 0 1 2, which is a list NB. subindex of 1 designates the cell 3 4 5, which is a list NB. subindex of 1 1 designates the cell 4, which is an atom
It follows that the rank of a cell of a noun is the difference between the rank of the noun and the length of the subindex. Calling this rank k, we say that the cell is a k-cell. A 0-cell is an atom, a 1-cell is a list, etc.
Not so fast, there! That last paragraph was really important. Make sure you can say it in your own words!
At a higher level, we say that any array can be thought of as an array of k-cells, where k is anything from 0 to the rank of the array.
For example, a table can be thought of as a table of atoms, or as a list of lists. A brick of shape 2 3 4 can be thought of as any of the following:
If k is greater than or equal to the rank of a noun, the noun has a single k-cell which is the entire noun. The frame of this cell is empty. The extreme case of this is when k is _ (infinity), which is always greater than the rank of any noun.
If k is negative, it is taken to refer to cells whose rank is the rank of the noun plus the (negative) k. Thus, _1-cells have rank 1 less than the noun, _2-cells have rank 2 less, and so on.
ItemsThe items of a noun are the _1-cells. Many J verbs operate on items.
The items of a list are atoms; the items of a table are lists; etc. An atom has one item, itself.
The sentence # y gives the number of items in y, its tally.
Empty ArraysA noun is empty if it contains no atoms. The simplest examples of empty arrays are the empty string '' and the empty numeric list 0$0.
An empty noun contains a 0 in its shape. An atom is not empty (the shape of an atom is empty, though).
$ '' NB. shape of empty string 0 $ 'a' NB. shape of atom
An empty array may have cells and items. For example, an array with shape 3 0 4 contains no atoms, but it has 3 2-cells, each with shape 0 4:
a =. i. 3 0 4 NB. an empty array $ a NB. its shape 3 0 4 #a NB. number of items 3Leading Ones In The Shape
There is a great difference between an atom and a 1-element list.
a =. 5 NB. An atom b =. ,a NB. A 1-element list $a NB. They have different shapes. $b 1 1 2 3 + a NB. They execute differently... 6 7 8 1 2 3 + b |length error | 1 2 3 +b a NB. ... but the display is identical 5 b 5
In general, leading 1s in the shape of a noun cannot be discerned from the display of the noun itself. You have to look at the shape of the noun.
a =. 0 1 2 3 NB. a list b =. ,: a NB. A table with 1 row a NB. The displays are identical... 0 1 2 3 b 0 1 2 3 $ a NB. ...but the shapes are different 4 $b 1 4The Value of a Noun
The value of a noun is the combination of its type, shape, and elements.
Elements are considered equal if they are of the same type and represent identical values in the type. 1 and 1.0 are the same number.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4