HOME

TheInfoList



OR:

The J
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is an
array programming In computer science, array programming refers to solutions which allow the application of operations to an entire set of values at once. Such solutions are commonly used in scientific and engineering settings. Modern programming languages that s ...
language based primarily on APL (also by Iverson). To avoid repeating the APL special-character problem, J uses only the basic
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because of ...
character set, resorting to the use of the dot and colon as ''inflections'' to form short words similar to '' digraphs''. Most such ''primary'' (or ''primitive'') J words serve as mathematical symbols, with the dot or colon extending the meaning of the basic characters available. Also, many characters which in other languages often must be paired (such as [] "" `` or <>) are treated by J as stand-alone words or, when inflected, as single-character roots of multi-character words. J is a very terse array programming language, and is most suited to
mathematical Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
and statistical programming, especially when performing operations on
matrices Matrix most commonly refers to: * ''The Matrix'' (franchise), an American media franchise ** ''The Matrix'', a 1999 science-fiction action film ** "The Matrix", a fictional setting, a virtual reality environment, within ''The Matrix'' (franchis ...
. It has also been used in
extreme programming Extreme programming (XP) is a software development methodology intended to improve software quality and responsiveness to changing customer requirements. As a type of agile software development,"Human Centred Technology Workshop 2006 ", 2006, P ...
and
network performance Network performance refers to measures of service quality of a network as seen by the customer. There are many different ways to measure the performance of a network, as each network is different in nature and design. Performance can also be model ...
analysis. Like
John Backus John Warner Backus (December 3, 1924 – March 17, 2007) was an American computer scientist. He directed the team that invented and implemented FORTRAN, the first widely used high-level programming language, and was the inventor of the Backu ...
's languages FP and FL, J supports
function-level programming In computer science, function-level programming refers to one of the two contrasting programming paradigms identified by John Backus in his work on programs as mathematical objects, the other being value-level programming. In his 1977 Turing A ...
via its ''
tacit programming Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions, among which are co ...
'' features. Unlike most languages that support
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
, J's flexible hierarchical
namespace In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
scheme (where every name exists in a specific ''locale'') can be effectively used as a framework for both
class-based Class-based programming, or more commonly class-orientation, is a style of object-oriented programming (OOP) in which inheritance (object-oriented programming), inheritance occurs via defining ''class (computer programming), classes'' of object ...
and prototype-based object-oriented programming. Since March 2011, J is
free and open-source software Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
under the
GNU General Public License The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the Four Freedoms (Free software), four freedoms to run, study, share, and modify the software. The license was th ...
version 3 (GPLv3).Jsoftware's source download page
/ref> One may also purchase source under a negotiated license.Jsoftware's sourcing policy
/ref>


Examples

J permits point-free style and
function composition In mathematics, function composition is an operation that takes two functions and , and produces a function such that . In this operation, the function is applied to the result of applying the function to . That is, the functions and ...
. Thus, its programs can be very terse and are considered difficult to read by some programmers. The "Hello, World!" program in J is: 'Hello, World!' This implementation of hello world reflects the traditional use of J – programs are entered into a J interpreter session, and the results of expressions are displayed. It's also possible to arrange for J scripts to be executed as standalone programs. Here's how this might look on a
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
system: #!/bin/jc echo 'Hello, world!' exit '' (Note that current j implementations install either jconsole or (because jconsole is used by java), ijconsole and likely install this to /usr/bin or some other directory (perhaps the Application directory on OSX). So, there's a system dependency here which the user would have to solve.) Historically, APL used / to indicate the fold, so +/1 2 3 was equivalent to 1+2+3. Meanwhile, division was represented with the mathematical division symbol (). Because ASCII does not include a division symbol ''per se'', J uses % to represent division, as a visual approximation or reminder. (This illustrates something of the mnemonic character of J's tokens, and some of the quandaries imposed by the use of ASCII.) Defining a J function named avg to calculate the average of a list of numbers yields: * +/ sums the items of the array. * # counts the number of items in the array. * % divides the sum by the number of items. This is a test execution of the function: 2.5 Above, ''avg'' is defined using a train of three verbs (+/, %, and #) termed a ''fork''. Specifically, (V0 V1 V2) Ny is the same as (V0(Ny)) V1 (V2(Ny)) which shows some of the power of J. (Here V0, V1, and V2 denote verbs and Ny denotes a noun.) Some examples of using avg: NB. a random vector 46 55 79 52 54 39 60 57 60 94 46 78 13 18 51 92 78 60 90 62 59.2 NB. moving average on periods of size 4 58 60 56 51.25 52.5 54 67.75 64.25 69.5 57.75 38.75 40 43.5 59.75 70.25 80 72.5 NB. a random matrix 46 5 29 2 4 39 10 7 10 44 46 28 13 18 1 42 28 10 40 12 NB. apply avg to each rank 1 subarray (each row) of m 17.2 22 21.2 26.4
Rank Rank is the relative position, value, worth, complexity, power, importance, authority, level, etc. of a person or object within a ranking, such as: Level or position in a hierarchical organization * Academic rank * Diplomatic rank * Hierarchy * ...
is a crucial concept in J. Its significance in J is similar to the significance of select in SQL and of while in C. Implementing
quicksort Quicksort is an efficient, general-purpose sorting algorithm. Quicksort was developed by British computer scientist Tony Hoare in 1959 and published in 1961, it is still a commonly used algorithm for sorting. Overall, it is slightly faster than ...
, from the J Dictionary yields: sel=: adverb def 'u # [' quicksort=: verb define if. 1 >: #y do. y else. (quicksort y sel e=.y{~?#y end. ) The following is an implementation of quicksort demonstrating
tacit programming Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions, among which are co ...
. The latter involves composing functions together and not referring explicitly to any variables. J's support for ''forks'' and ''hooks'' dictates rules on how arguments applied to this function will be applied to its component functions. quicksort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1<#) Sorting in J is usually accomplished using the built-in (primitive) verbs /: (sort up) and \: (sort down). User-defined sorts such as quicksort, above, typically are for illustration only. The following example demonstrates the usage of the self-reference verb $: to recursively calculate fibonacci numbers: 1:`($:@-&2+$:@<:)@.(>&2) This recursion can also be accomplished by referring to the verb by name, although this is of course only possible if the verb is named: fibonacci=:1:`(fibonacci@-&2+fibonacci@<:)@.(>&2) The following expression exhibits pi with n digits and demonstrates the extended precision abilities of J: NB. set n as the number of digits required NB. extended precision 10 to the nth * pi 314159265358979323846264338327950288419716939937510


Verbs and Modifiers

A program or routine - something that takes data as input and produces data as output - is called a ''verb''. J has a rich set of predefined verbs, all of which work on multiple data types automatically: for example, the verb searches within arrays of any size to find matches: 3 1 4 1 5 9 i. 3 1 NB. find the index of the first occurrence of 3, and of 1 0 1 3 1 4 1 5 9 i: 3 1 NB. find the index of the last occurrence of 3, and of 1 0 3 User programs can be named and used wherever primitives are allowed. The power of J comes largely from its ''modifiers'': symbols that take nouns and verbs as operands and apply the operands in a specified way. For example, the modifier takes one operand, a verb to its left, and produces a verb that applies that verb between each item of its argument. That is, is a verb, defined as 'apply between the items of your argument' Thus, the sentence +/ 1 2 3 4 5 produces the effect of 1 + 2 + 3 + 4 + 5 +/ 1 2 3 4 5 15 J has roughly two dozen of these modifiers. All of them can apply to any verb, even a user-written verb, and users may write their own modifiers. While modifiers are powerful individually, allowing * repeated execution, i. e. ''do-while'' * conditional execution, i. e. ''if'' * execution of regular or irregular subsets of arguments some of the modifiers control the order in which components are executed, allowing modifiers to be combined in any order to produce the unlimited variety of operations needed for practical programming.


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, 1 0 1 0 1 1 0 0 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 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 1 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 are never tokens alone, unless preceded by
whitespace character In computer programming, whitespace is any character or series of characters that represent horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area ...
s.) 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 Unicode, formally The Unicode Standard,The formal version reference is is an information technology Technical standard, standard for the consistent character encoding, encoding, representation, and handling of Character (computing), text expre ...
). 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 < operation (with no left argument; if there's a left argument, this would be the ''less than'' operation). This is analogous to C's & operation (with no 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 allows working with an array of boxes (it can be assembled with other boxes, and/or more copies can be made of the box). <1 0 0 1 0 +---------+ , 1 0 0 1 0, +---------+ 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 1 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 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,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. Another pseudo-type—associated with name, rather than value—is the memory mapped file.


Debugging

J has the usual facilities for stopping on error or at specified places within verbs. It also has a unique visual debugger, calle
''Dissect''
that gives a 2-D interactive display of the execution of a single J sentence. Because a single sentence of J performs as much computation as an entire subroutine in lower-level languages, the visual display is quite helpful.


Documentation

J's documentation includes
dictionary
with words in J identified a
nounsverbsmodifiers
and so on. Primary words are listed in th
vocabulary
in which their respectiv
parts of speech
are indicated using markup. Note that verbs have two forms: monadic (arguments only on the right) and dyadic (arguments on the left and on the right). For example, in '-1' the hyphen is a monadic verb, and in '3-2' the hyphen is a dyadic verb. The monadic definition is mostly independent of the dyadic definition, regardless of whether the verb is a primitive verb or a derived verb.


Control structures

J provides control structure
(details here)
similar to other procedural languages. Prominent control words in each category include: * assert. * break. * continue. * for. * goto_label. * if. else. elseif. * return. * select. case. * throw. * try. catch. * while. whilst.


See also

*
K (programming language) K is a proprietary array processing programming language developed by Arthur Whitney and commercialized by Kx Systems. The language serves as the foundation for kdb+, an in-memory, column-based database, and other related financial products. T ...
– another APL-influenced language * Q – The language of KDB+ and a new merged version of K and KSQL.


References


External links

* – JSoftware, creators of J * – Repository of source
J Wiki


– An Introduction to the J Programming Language by Roger Stokes {{DEFAULTSORT:J (Programming Language) APL programming language family Array programming languages Class-based programming languages Dynamically typed programming languages Function-level languages Functional languages Multi-paradigm programming languages Numerical programming languages Object-oriented programming languages