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
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)
Categories: Programming languages | Function-level languages | Array programming languages | Numerical programming languages | Multi-paradigm programming languages | Object-oriented programming languages | Class-based programming languages | Dynamic programming languages | APL programming language family | Dynamically-typed programming languages