J programming language

The J programming language, developed in the early 90's by Ken Iverson and Roger Hui, is a synthesis of APL (also by Iverson) and the FP and FL functional programming languages created by John Backus (of FORTRAN, ALGOL, and BNF fame).

To avoid the problems faced by the special character set of APL, J requires only the basic ASCII character set, resorting to the use of dot and colon characters to extend the meaning of the basic characters available.

Being an array programming language, J is very terse and powerful, and is often found to be useful for mathematical and statistical programming, especially when performing operations on matrices.

Like the original FP/FL languages, J supports function-level programming (also known as higher-order functional programming), via its tacit programming features (note that function-level programming is not the same as functional programming).

Unlike most languages that support object-oriented programming, J's flexible hierarchichal namespace scheme (where every name exists in a particular locale) can be effectively used as a framework for both class-based and instance-based object oriented programming.

J is an non-von Neumann programming language that nevertheless allows the programmer to use von Neumann programming style when desired.


Contents

Hello world

'Hello world'

Examples

J is an extremely powerful language, and its programs can be very terse but even more cryptic. Here is a one-liner implementation of the quicksort algorithm:

  qsort =: ]`(($:@:((}.<:{.)#}.)),{.,($:@:((}.>{.)#}.)))@.(*@#)

But if we define some intermediate mnemonic names (NB. introduces a comment, think Nota Bene):

  id        =: ]                                 NB. identity function
  choose    =: @.                                NB. conditional execution
  first     =: {.                                NB. first element of collection
  rest      =: }.                                NB. all elements but first of collection
  o         =: @:                                NB. function composition:  f o g (x)  =   f(g(x))
  void      =: [:
  sign      =: * : void                          NB. monadic only, void dyadic
  length    =: # : void                          NB. monadic only, void dyadic
  selfrom   =: void : #                          NB. dyadic only, void monadic
  notEmpty  =: sign o length                     NB. sign 0 = 0


Then the J qsort becomes much more readable:

  selLEF    =: (rest <: first) selfrom rest      NB. select Less-than or Equal to First
  selGTF    =: (rest >  first) selfrom rest      NB. select Greater-Than First
 
  qsort  =: id ` (($: o selLEF),first,($: o selGTF))  choose notEmpty

Note particularly that this is an anonymous recursive function. J provides the self reference operator $: to refer anonymously to the largest enclosing context. Very few languages are capable of expressing this.

The following expression (thanks to Roger Hui) computes n digits of pi and demonstrates the extended precision capabilities of J:

 n=.50                                           NB. set n as the number of digits required
 <.@o. 10x^n                                     NB. extended precision 10 to the nth * pi
314159265358979323846264338327950288419716939937510

Also have a look at Cliff Reiter's implementation of Conway's game of life at http://ww2.lafayette.edu/~reiterc/j/vector/vlife_index.html

Vocabulary

= Self-Classify • Equal =. Is (Local) =: Is (Global)
< Box • Less Than <. Floor • Lesser Of (Min) <: Decrement • Less Or Equal
> Open • Larger Than >. Ceiling • Larger of (Max) >: Increment • Larger Or Equal
_ Negative Sign / Infinity _. Indeterminate _: Infinity
 
+ Conjugate • Plus +. Real / Imaginary • GCD (Or) +: Double • Not-Or
* Signum • Times *. Length/Angle • LCM (And) *: Square • Not-And
- Negate • Minus -. Not • Less -: Halve • Match
% Reciprocal • Divide %. Matrix Inverse • Matrix Divide %: Square Root • Root
 
^ Exponential • Power ^. Natural Log • Logarithm ^: Power (u^:n u^:v)
$ Shape Of • Shape $. Sparse $: Self-Reference
~ Reflex</b> • <b>Passive</b> / EVOKE ~. Nub • ~: Nub Sieve • Not-Equal
| Magnitude • Residue |. Reverse • Rotate (Shift) |: Transpose
 
. <b>Determinant • Dot Product .. Even .: Odd
: Explicit / Monad-Dyad :. Obverse :: Adverse
, Ravel • Append ,. Ravel Items • Stitch ,: Itemize • Laminate
; Raze • Link ;. Cut ;: Words • Sequential Machine
 
# Tally • Copy #. Base 2 • Base #: Antibase 2 • Antibase
! Factorial • Out Of !. Fit (Customize) !: Foreign
/ Insert</b> • <b>Table</b> /. <b>Oblique</b> • <b>Key</b> /: Grade Up • Sort
\ <b>Prefix</b> • <b>Infix</b> \. <b>Suffix</b> • <b>Outfix</b> \: Grade Down • Sort
 
[ Same • Left   [: Cap
] Same • Right    
{ Catalogue • From {. Head • Take {: Tail •   {:: Map • Fetch
} <b>Item Amend • Amend (m} u}) }. Behead • Drop }: Curtail •
 
" Rank (m"n u"n m"v u"v) ". Do • Numbers ": Default Format • Format
` Tie (Gerund)   `: Evoke Gerund
@ Atop @. Agenda @: At
& Bond / Compose &. &.: Under (Dual) &: Appose
? Roll • Deal ?. Roll • Deal (fixed seed)
 
a. Alphabet a: Ace (Boxed Empty) A. Anagram Index • Anagram
b. Boolean / Basic</b> C. Cycle-Direct • Permute d. <b>Derivative
D. Derivative D: Secant Slope e. Raze In • Member (In)
E. • Member of Interval f. Fix</b> H. <b>Hypergeometric
 
i. Integers • Index Of i: Integers • Index Of Last I. Indices •
j. Imaginary • Complex L. Level Of L: Level At
m. n. Explicit Noun Arguments NB. Comment o. Pi Times • Circle Function
p. Polynomial p.. Poly. Deriv. • Poly. Integral p: Primes •
 
q: Prime Factors • Prime Exponents   r. Angle • Polar s: Symbol
S: Spread t. Taylor Coefficient</b> t: <b>Weighted Taylor</b>
T. <b>Taylor Approximation u. v. Explicit Verb Arguments u: Unicode
x. y. Explicit Arguments x: Extended Precision _9: to 9: Constant Functions

See also

Function-level programming
Related programming languages:  APL, FP, FL, NGL, K

External links

  • JSoftware (http://www.jsoftware.com) Creators of J (currently free for all uses)
  • Cliff Reiter (http://ww2.lafayette.edu/~reiterc) Chaos, fractals and mathematical symmetries... in J
  • Ewart Shaw (http://www.ewartshaw.co.uk/) Bayesian inference, medical statistics, and numerical methods, using J
  • Keith Smillie (http://www.cs.ualberta.ca/~smillie) Statistical applications of array programming languages, especially J
  • John Howland (http://www.cs.trinity.edu/~jhowland) Research on parallelization of array programming languages, especially Jfr:J (langage)

zh:J语言

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools