Data Types and Structures
J supports three simple types:
- Numeric
- Literal (Character)
- Boxed
Of these, numeric has the most variants.
One of J's numeric types is the bit. There are two bit values: 0, and 1. Additionally, bits can be formed into lists. For example, 1 0 1 0 1 1 0 0
is a list of eight bits. Syntactically, the J parser treats that as a single word. (The space character is recognized as a word-forming character between what would otherwise be numeric words.) Lists of arbitrary length are supported.
Furthermore, J supports all the usual binary operations on these lists, such as and, or, exclusive or, rotate, shift, not, etc. For example,
1 0 0 1 0 0 1 0 +. 0 1 0 1 1 0 1 0 NB. or 1 1 0 1 1 0 1 0 3 |. 1 0 1 1 0 0 1 1 1 1 1 NB. rotate 1 0 0 1 1 1 1 1 1 0 1Note that J also supports higher order arrays of bits—they can be formed into two-dimensional, three-dimensional, etc. arrays. The above operations perform equally well on these arrays.
Other numeric types include integer (e.g. 3, 42), floating point (3.14, 8.8e22), complex (0j1, 2.5j3e88), extended precision integer (12345678901234567890x), and (extended precision) rational fraction (1r2, 3r4). As with bits, these can be formed into lists or arbitrarily dimensioned arrays. As with bits, operations are performed on all numbers in an array.
Lists of bits can be converted to integer using the #.
verb. Integers can be converted to lists of bits using the #:
verb. (When parsing J, .
(period) and :
(colon) are word-forming characters. They're never tokens by themselves unless preceded by whitespace.)
J also supports the literal (character) type. Literals are enclosed in quotes, for example, 'a'
or 'b'
. Lists of literals are also supported using the usual convention of putting multiple characters in quotes, such as 'abcdefg'
. Typically, individual literals are 8-bits wide (ASCII), but J also supports other literals (Unicode). Numeric and boolean operations are not supported on literals, but collection-oriented operations (such as rotate) are supported.
Finally, there's the boxed data type. Typically, data is put in a box using the <
operation (without any left argument—if there's a left argument, this would be the 'less than' operation). This is analogous to C's &
operation (without any left argument). However, where the result of C's &
has reference semantics, the result of J's <
has value semantics. In other words, < is a function and it produces a result. The result has 0 dimensions, regardless of the structure of the contained data. From the viewpoint of a J programmer, <
'puts the data into a box' and lets the programmer work with an array of boxes (it can be assembled with other boxes, and/or additional copies can be made of the box). Boxed data is displayed by J, somewhat after the fashion some SQL interpreters decorate table results from select statements.
The only collection type offered by J is the arbitrarily dimensioned array. Most algorithms can be expressed very concisely using operations on these arrays.
J's arrays are homogeneously typed, for example the list 1 2 3
is a list of integers despite the fact that 1
is a bit. For the most part, these sorts of type issues are transparent to the programmer. Only certain specialized operations reveal differences in type. For example, the list 1.0 0.0 1.0 0.0
would be treated exactly the same, by most operations, as the list 1 0 1 0
.
J also supports sparse numeric arrays where non-zero values are stored with their indices. This is an efficient mechanism where relatively few values are non-zero.
J also supports objects and classes, but these are an artifact of the way things are named, and are not data types in and of themselves. Instead, boxed literals are used to refer to objects (and classes). J data has value semantics, but objects and classes need reference semantics.
Another pseudo-type—associated with name, rather than value—is the memory mapped file.
Read more about this topic: J (programming Language)
Famous quotes containing the words data, types and/or structures:
“Mental health data from the 1950s on middle-aged women showed them to be a particularly distressed group, vulnerable to depression and feelings of uselessness. This isnt surprising. If society tells you that your main role is to be attractive to men and you are getting crows feet, and to be a mother to children and yours are leaving home, no wonder you are distressed.”
—Grace Baruch (20th century)
“The wider the range of possibilities we offer children, the more intense will be their motivations and the richer their experiences. We must widen the range of topics and goals, the types of situations we offer and their degree of structure, the kinds and combinations of resources and materials, and the possible interactions with things, peers, and adults.”
—Loris Malaguzzi (19201994)
“It is clear that all verbal structures with meaning are verbal imitations of that elusive psychological and physiological process known as thought, a process stumbling through emotional entanglements, sudden irrational convictions, involuntary gleams of insight, rationalized prejudices, and blocks of panic and inertia, finally to reach a completely incommunicable intuition.”
—Northrop Frye (b. 1912)