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)
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!
{{Short description|Programming language}} {{Infobox programming language | name = J | logo = J (programming language) icon.png | file_ext = | paradigm = [[Array programming|Array]], [[Functional programming|functional]], [[Object-oriented programming|object-oriented]] ([[Class-based programming|class-based]], [[Prototype-based programming|prototype-based]]), [[Function-level programming|function-level]], [[Tacit programming|tacit]] | released = {{Start date and age|1990}} | designer = [[Kenneth E. Iverson]], [[Roger Hui]] | developer = JSoftware | latest release version = J9.6 | latest release date = {{Start date and age|2025|02|25|df=yes}}<ref>{{cite web |url= https://code.jsoftware.com/wiki/System/ReleaseNotes/J9.6 |title= Release Notes J9.6}}</ref> | latest preview version = | latest preview date = | typing = [[dynamic typing|dynamic]] | implementations = J | dialects = | influenced by = [[APL (programming language)|APL]] | influenced = [[NumPy]],<ref name="Python for Data Analysis">[http://traims.tumblr.com/post/33883718232/python-for-data-analysis-18-oct-2012-london Wes McKinney at 2012 meeting Python for Data Analysis]</ref> [[SuperCollider]]<ref name="SuperCollider documentation">[http://doc.sccode.org/Reference/Adverbs.html SuperCollider documentation, Adverbs for Binary Operators]</ref> | operating system = [[Cross-platform]]: [[Microsoft Windows|Windows]], [[Linux]], [[macOS]], [[Android (operating system)|Android]], [[iOS]], [[Raspberry Pi]]<ref>{{Cite web|url=https://www.jsoftware.com/#/README|title = Jsoftware}}</ref> | license = [[GNU General Public License|GPLv3]] | website = {{URL|www.jsoftware.com}} | wikibooks = }} The '''J''' [[programming language]], developed in the early 1990s by [[Kenneth E. Iverson]] and [[Roger Hui]],<ref>[https://web.archive.org/web/20040812193452/http://home1.gte.net/res057qw/APL_J/IversonAPL.htm A Personal View of APL], 1991 essay by K.E. Iverson (archived link)</ref><ref>[http://jsoftware.com/pipermail/general/2002-March/010962.html Overview of J history] by Roger Hui (19 March 2002)</ref> is an [[array programming]] language based primarily on [[APL (programming language)|APL]] (also by Iverson). To avoid repeating the APL special-character problem, J uses only the basic [[ASCII]] character set, resorting to the use of the dot and colon as ''inflections''<ref>[http://code.jsoftware.com/wiki/Vocabulary/Words J NuVoc Words]</ref> to form short words similar to ''[[digraph (computing)|digraph]]s''. 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 <code>[] {} "" ``</code> or <code><></code>) 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]] and [[statistical]] programming, especially when performing operations on [[matrix (mathematics)|matrices]]. It has also been used in [[extreme programming]]<ref>{{Cite book |title= Software Development as a Collaborative Writing Project |series= Extreme programming and agile processes in software engineering |place= Oulu, Finland |year= 2006 |first1= Brian |last1= Bussell |first2= Stephen |last2= Taylor |pages= 21–31 |publisher= [[Springer Science+Business Media|Springer]] |isbn= 978-3-540-35094-1}}</ref> and [[network performance]] analysis.<ref>{{Cite book |first= Alan |last= Holt |title= Network Performance Analysis: Using the J Programming Language |isbn= 978-1-84628-822-7 |year= 2007 |publisher= [[Springer Science+Business Media|Springer]]}}</ref> Like [[John Backus]]'s languages [[FP (programming language)|FP]] and [[FL (programming language)|FL]], J supports [[function-level programming]] via its ''[[tacit programming]]'' features. Unlike most languages that support [[object-oriented programming]], J's flexible hierarchical [[namespace]] scheme (where every name exists in a specific ''locale'') can be effectively used as a framework for both [[class-based programming|class-based]] and [[prototype-based programming|prototype-based]] object-oriented programming. Since March 2011, J is [[free and open-source software]] under the [[GNU General Public License]] version 3 (GPLv3).<ref name="j source download">[https://www.jsoftware.com/#/source Jsoftware's source download page]</ref><ref name="j_gpl">{{cite web |url= http://thread.gmane.org/gmane.comp.lang.j.programming/20882 |title= J Source GPL |date= 1 March 2011 |author= Eric Iverson |work= J programming mailing list |access-date= 24 June 2015 |archive-date= 23 September 2016 |archive-url= https://web.archive.org/web/20160923133425/http://thread.gmane.org/gmane.comp.lang.j.programming/20882 |url-status= dead }}</ref><ref>{{github|openj/core|openj}}</ref> One may also purchase source under a negotiated license.<ref name="j_source">[https://www.jsoftware.com/#/source Jsoftware's sourcing policy]</ref> ==Examples== J permits [[tacit programming|point-free style]] and [[function composition (computer science)|function composition]]. Thus, its programs can be very terse and are considered difficult to read by some programmers. The [["Hello, World!" program]] in J is: <syntaxhighlight lang="j"> 'Hello, World!' </syntaxhighlight> 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]] system: <syntaxhighlight lang="j"> #!/bin/jc echo 'Hello, world!' exit '' </syntaxhighlight> (Note that current j implementations install either <code>jconsole</code> or (because jconsole is used by java), <code>ijconsole</code> 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 <code>/</code> to indicate the [[fold (higher-order function)|fold]], so <code>+/1 2 3</code> was equivalent to <code>1+2+3</code>. Meanwhile, division was represented with the mathematical [[division symbol]] ({{code|÷}}). 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 <code>avg</code> to calculate the average of a list of numbers yields: {{code|2=j|1=avg=: +/ % #}} * <code> +/ </code>sums the items of the array. * <code> # </code>counts the number of items in the array. * <code> % </code>divides the sum by the number of items. This is a test execution of the function: {{code|2=j|1=avg 1 2 3 4}} <span style="color:sienna;">2.5</span> Above, ''avg'' is defined using a train of three verbs (<code>+/</code>, <code>%</code>, and <code>#</code>) termed a ''fork''. Specifically, <code>(V0 V1 V2) Ny</code> is the same as <code>(V0(Ny)) V1 (V2(Ny))</code> which shows some of the power of J. (Here V0, V1, and V2 denote verbs and Ny denotes a noun.) Some examples of using <code>avg</code>: {{code|2=j|1=v=: ?. 20 $100}} <span style="color:gray;">NB. a random vector</span> {{code|v}} <span style="color:sienna">46 55 79 52 54 39 60 57 60 94 46 78 13 18 51 92 78 60 90 62</span> {{code|2=j|1=avg v}} <span style="color:sienna;">59.2</span> {{code|2=j|1=4 avg\ v}} <span style="color:gray;">NB. moving average on periods of size 4</span> <span style="color:sienna;">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</span> {{code|2=j|1=m=: ?. 4 5 $50}} <span style="color:gray;">NB. a random matrix</span> {{code|m}} <span style="color:sienna;">46 5 29 2 4 39 10 7 10 44 46 28 13 18 1 42 28 10 40 12</span> {{code|2=j|1=avg"1 m}} <span style="color:gray;">NB. apply avg to each rank 1 subarray (each row) of m</span> <span style="color:sienna;">17.2 22 21.2 26.4</span> [[Rank (J programming language)|Rank]] is a crucial concept in J. Its significance in J is similar to the significance of <code>select</code> in [[SQL]] and of <code>while</code> in [[C (programming language)|C]]. Implementing [[quicksort]], from the J Dictionary yields: <syntaxhighlight lang="j"> sel=: adverb def 'u # [' quicksort=: verb define if. 1 >: #y do. y else. (quicksort y <sel e),(y =sel e),quicksort y >sel e=.y{~?#y end. ) </syntaxhighlight> The following is an implementation of quicksort demonstrating [[tacit programming]]. 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. <syntaxhighlight lang="j"> quicksort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1<#) </syntaxhighlight> Sorting in J is usually accomplished using the built-in (primitive) verbs <code>/:</code> (sort up) and <code>\:</code> (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 <code>$:</code> to recursively calculate fibonacci numbers: <syntaxhighlight lang="j"> 1:`($:@-&2+$:@<:)@.(>&2) </syntaxhighlight> This recursion can also be accomplished by referring to the verb by name, although this is of course possible only if the verb is named: <syntaxhighlight lang="j"> fibonacci=:1:`(fibonacci@-&2+fibonacci@<:)@.(>&2) </syntaxhighlight> The following expression exhibits [[pi]] with n digits and demonstrates the extended precision abilities of J: {{code|2=j|1=n=: 50}} <span style="color:gray;">NB. set n as the number of digits required</span> {{code|2=j|1=<.@o. 10x^n}} <span style="color:gray;">NB. extended precision 10 to the nth * pi</span> <span style="color:sienna;">314159265358979323846264338327950288419716939937510</span> ==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 {{mono|i.}} searches within arrays of any size to find matches: <syntaxhighlight lang="j"> 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 </syntaxhighlight> 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 {{mono|/}} takes one operand, a verb to its left, and produces a verb that applies that verb between each item of its argument. That is, {{mono|+/}} is a verb, defined as 'apply {{mono|+}} between the items of your argument' Thus, the sentence <syntaxhighlight lang="j"> +/ 1 2 3 4 5 </syntaxhighlight> produces the effect of <syntaxhighlight lang="j"> 1 + 2 + 3 + 4 + 5 +/ 1 2 3 4 5 15 </syntaxhighlight> 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, <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. ==Debugging== [[File:Dissect example Collatz.png|thumb|Dissecting the Collatz sequence starting from 6]] J has the usual facilities for stopping on error or at specified places within verbs. It also has a unique visual debugger, called [http://code.jsoftware.com/wiki/Vocabulary/Dissect ''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 a [http://code.jsoftware.com/wiki/NuVoc dictionary], with words in J identified as [http://code.jsoftware.com/wiki/Vocabulary/Nouns nouns], [http://code.jsoftware.com/wiki/Vocabulary/Verbs verbs], [http://code.jsoftware.com/wiki/Vocabulary/Modifiers modifiers], and so on. Primary words are listed in the [http://code.jsoftware.com/wiki/Vocabulary/Words vocabulary], in which their respective [http://code.jsoftware.com/wiki/Vocabulary/PartsOfSpeech parts of speech] are indicated using markup. Note that verbs have two forms: [[Arity|monadic]] (arguments only on the right) and [[Arity|dyadic]] (arguments on the left and on the right). For example, in '<code>-1</code>' the hyphen is a monadic verb, and in '<code>3-2</code>' 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 structures [http://jsoftware.com/help/dictionary/ctrl.htm (details here)] similar to other procedural languages. Prominent control words in each category include: * <code>assert.</code> * <code>break.</code> * <code>continue.</code> * <code>for.</code> * <code>goto_label.</code> * <code>if. else. elseif.</code> * <code>return.</code> * <code>select. case.</code> * <code>throw.</code> * <code>try. catch.</code> * <code>while. whilst.</code> ==See also== * [[K (programming language)]] – another APL-influenced language * [[Q (programming language from Kx Systems)|Q]] – The language of KDB+ and a new merged version of K and KSQL. ==References== {{Reflist}} ==External links== * {{Official website|www.jsoftware.com}} – JSoftware, creators of J * {{GitHub|jsoftware/jsource}} – Repository of source * [https://code.jsoftware.com/wiki/Main_Page J Wiki] * [http://www.jsoftware.com/help/learning/contents.htm Learning J] – An Introduction to the J Programming Language by Roger Stokes {{Use dmy dates|date=April 2020}} {{APL programming language}} {{Authority control}} {{DEFAULTSORT:J (Programming Language)}} [[Category:APL programming language family]] [[Category:Array programming languages]] [[Category:Class-based programming languages]] [[Category:Dynamically typed programming languages]] [[Category:Function-level languages]] [[Category:Functional languages]] [[Category:Multi-paradigm programming languages]] [[Category:Numerical programming languages]] [[Category:Object-oriented programming languages]]
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)
Pages transcluded onto the current version of this page
(
help
)
:
Template:APL programming language
(
edit
)
Template:Authority control
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:GitHub
(
edit
)
Template:Github
(
edit
)
Template:Infobox programming language
(
edit
)
Template:Mono
(
edit
)
Template:Official website
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)