Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
J (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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''. Also, bits can be formed into lists. For example, <code> 1 0 1 0 1 1 0 0 </code> is a list of eight bits. Syntactically, the J parser treats that as one word. (The space character is recognized as a word-forming character between what would otherwise be numeric words.) Lists of arbitrary length are supported. Further, 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 <span style="color:gray">NB. or</span> <span style="color:sienna">1 1 0 1 1 0 1 0</span> 3 |. 1 0 1 1 0 0 1 1 1 1 1 <span style="color:gray">NB. rotate</span> <span style="color:sienna">1 0 0 1 1 1 1 1 1 0 1</span> 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 <code>#.</code> verb. Integers can be converted to lists of bits using the <code>#:</code> verb. (When parsing J, <code>.</code> (period) and <code>:</code> (colon) are word-forming characters. They are never tokens alone, unless preceded by [[whitespace character]]s.) J also supports the literal (character) type. Literals are enclosed in quotes, for example, <code>'a'</code> or <code>'b'</code>. Lists of literals are also supported using the usual convention of putting multiple characters in quotes, such as <code>'abcdefg'</code>. 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 is a boxed data type. Typically, data is put in a box using the <code><</code> operation (with no left argument; if there's a left argument, this would be the ''less than'' operation). This is analogous to [[C (programming language)|C]]'s <code>&</code> operation (with no left argument). However, where the result of C's <code>&</code> has reference semantics, the result of J's <code><</code> has value semantics. In other words, <code><</code> 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, <code><</code> ''puts the data into a box'' and allows working with an array of boxes (it can be assembled with other boxes or more copies can be made of the box). <1 0 0 1 0 <span style="color:sienna">+---------+ |1 0 0 1 0| +---------+</span> 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 <code> 1 2 3 </code> is a list of integers despite <code> 1 </code> being a bit. For the most part, these sorts of type issues are transparent to programmers. Only certain specialized operations reveal differences in type. For example, the list <code> 1.0 0.0 1.0 0.0 </code> would be treated exactly the same, by most operations, as the list <code> 1 0 1 0 </code>. 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,<ref>[http://www.jsoftware.com/help/learning/25.htm Chapter 25: Object-Oriented Programming]</ref> but these are an artifact of the way things are named, and are not data types. Instead, boxed literals are used to refer to objects (and classes). J data has value semantics, but objects and classes need reference semantics.{{Citation needed|date=March 2017}} Another pseudo-type—associated with name, rather than value—is the memory mapped file.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)