Search

The Online Encyclopedia and Dictionary

 
     
 

Encyclopedia

Dictionary

Quotes

   
 

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 =: ]`(($:@:((}.<:{.)#}.)),{.,($:@:((}.>{.)#}.)))@.(*@#)

(No, it is not Linear A script.) 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 " Passive / EVOKE ~. Nub " ~: Nub Sieve " Not-Equal
| Magnitude " Residue |. Reverse " Rotate (Shift) |: Transpose
 
. 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 " Table /. Oblique " Key /: Grade Up " Sort
\ Prefix " Infix \. Suffix " Outfix \: Grade Down " Sort
 
[ Same " Left   [: Cap
] Same " Right    
{ Catalogue " From {. Head " Take {: Tail "   {:: Map " Fetch
} 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 C. Cycle-Direct " Permute d. Derivative/td>
D. Derivative D: Secant Slope e. Raze In " Member (In)
E. " Member of Interval f. Fix H. 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 t: Weighted Taylor
T. 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 Creators of J (currently free for all uses)
  • Cliff Reiter Chaos, fractals and mathematical symmetries... in J
  • Ewart Shaw Bayesian inference, medical statistics, and numerical methods, using J
  • Keith Smillie Statistical applications of array programming languages, especially J
  • John Howland Research on parallelization of array programming languages, especially J

Last updated: 05-07-2005 16:18:31
Last updated: 05-13-2005 07:56:04