Programming language J (2024)

J is an array programming language, developed in 1990 by Kenneth Iverson and Roger Hui. It is a synthesis of APL (earlier language by Iverson) and FP and FL languages created by John Backus.

Despite sharing the concept and the author with APL, J differs from it quite a lot. For example, J has no concept of a variable — it’s a function-level language, so the best it has are function renames. The authors also dropped special characters from the notation — the programs are written using 7-bit ASCII charset, and each function is written with at most two characters.

A distinctive feature of J is using grammar terms to describe entities of the program. Data pieces are called nouns, functions are verbs, and functions-creating operators are adverbs. Note that J allows to create user-defined adverbs, without restricting the programmer to the built-in ones.

Same as APL, J has only one data structure — hom*ogenous arrays of arbitrary dimensions. To organize more complex data structures, one can use boxing principle inherited from APL.

J introduces a set of block-oriented flow controls typical for procedural languages: loops, conditional statements and exception handlers.

Unlike APL, J programs and data are stored not in workspaces but in script files available to any text editor.

Examples:

Hello, World!:

Example for versions j602

1!:2 is the dyadic foreign conjunction for writing text, the left argument is the string to be written and the right argument specifies the file number, a file number 2 indicates that the text is to be written to the screen.

Alternatively we can use currying to convert the dyadic write conjunction into a monadic conjunction using the bond (&) operator and assign it to a named print function.

The printf library may also be used to print text to the screen.

'Hello, World!' 1!:2]2print=: 1!:2&2print 'Hello, World!'load 'printf''' printf 'Hello, World!\n'

Fibonacci numbers:

Example for versions j602

This example uses the recursive definition of Fibonacci numbers. @.(agenda) is a higher order dyadic function taking an array of functions(a gerund, created by tying together individual functions using the tie conjunction represented by a back-tick character) on the left and a function on the right that computes the index of the function in the function array(gerund) to be applied on the called argument.

The general call to agenda:

f1`f2@.g x

The function g is used to calculate an index using the argument x, this index is then used to select the function to be applied from the left argument of agenda, the function array. The function that is selected is then applied to the original argument x.

In the case of the above Fibonacci function, applying the semantics of the agenda function we get a function which checks whether its argument is less than two, if it is then 1 is returned otherwise the formal recursive calculation of the Fibonacci number is called on the argument.

load 'printf'fibr=: 1:`(-&2 +&$: -&1)@.(2&<)"0fstr=: '...' ,~ ,~^:4 '%d, 'fstr printf fibr >: i.16

Fibonacci numbers:

Example for versions j602

This example uses iterative definition of Fibonacci numbers.

load 'printf'fibi=: 3 : '(,+/@(_2&{.))^:y(0 1)'fstr=: '...' ,~ ,~^:4 '%d, 'fstr printf }.fibi 15

Fibonacci numbers:

Example for versions j602

This example uses Binet’s formula.

g =: -: >: %:5 is equivalent to g =: 0.5 * (1 + 5 ^ 0.5) and assigns name g to value of golden ratio. %: extracts square root of the number, >: increments the number, -: divides the number by two. Operations are done from right to left, unless there are no parenthesis in the formula.

fibb=: (%:5) %~ g&^ -- (1-g)&^ is equivalent to fibb =: (0.2 ^ 0.5) * (g &^ -- (1-g) &^); this defines a formula for F(n) given the value of n. %~ is division, with dividend and divisor swapped.

i.16 generates numbers from 0 to 15, inclusive.

load 'printf'g=: -: >: %:5fibb=: (%:5) %~ g&^ - (1-g)&^fstr=: '...' ,~ ,~^:4 '%d, 'fstr printf fibb 1+i.16

Factorial:

Example for versions j602

This example implements three methods of calculating factorial. fact represents a factorial function which generates the first n integers as an array and multiplies them together. factr represents the recursive definition. ! is the built-in factorial function.

load 'printf'fact=: [: */ [: >: i.factr=: 1:`(]*$:@<:)@.*'!%d = %d' printf (,"0 fact) i.17x'!%d = %d' printf (,"0 factr) i.17x'!%d = %d' printf (,"0 !) i.17x

Quadratic equation:

Example for versions j602

Run calc'' in an interactive J session after loading the file. The function calc2 calculates the roots of the equation using J’s built in root function(p.).

print=: 1!:2&2read=: 3 : '". 1!:1[1'a=: 0&{ [ b=: 1&{ [ c=: 2&{d=: *:@b - [:*/4,a,croots=: ([:-b%2*a)`(+:@a %~ (,-)@%:@d + -@b)@.([:*/*)input=: 3 : 0A=: read'' [ print 'A = 'B=: read'' [ print 'B = 'C=: read'' [ print 'C = ')calc=: 3 : 0input''if. A=0 do. print 'Not a quadratic equation' throw. end.rt=: roots A,B,Cdisp rt)disp=: 3 : 0form=: ((('('&,)@":@{.,',',(,&')')@":@}.)@+.)`":@.(=+)if. 1<# ~.y do. print 'x1 = ', form 0{y print 'x2 = ', form 1{yelse. print 'x = ', form {.yend.)calc2=: 3 : 0input''rt=: ;}.p.|.A,B,Cdisp rt)

Fibonacci numbers:

Example for versions j602

Maxtrix closed form

load 'printf'mat =: 1 1,.1 0fibm=: 3 : '1 { , mat&(+/ . *)^:y mat'"0fstr=: '...' ,~ ,~^:4 '%d, 'fstr printf fibm >:i.16

Programming language J (1)
Fibonacci Matrix Closed Form

CamelCase:

Example for versions j602

alpha is the set of upper and lower case alphabetic characters.

camel is an explicit solution to the problem, meaning that the variables to the function(y) are mentioned in the function body. The strategy used is to calculate the indices(i) of the alphabetic characters from the bit vector(b) which represents whether or not a character is alphabetic. The function then takes the leading index of each interval of these alphabetic characters and uses that to replace them by their capitalized form. Finally the string is sieved using b so that it contains only the alphabetic characters.

camel2 is a tacit definition, it cuts the input string at the delimiters(non-alphabetic characters), leaving a collection of boxed strings. The leading character of each of these boxed strings is then capitalized and they are all concatenated together forming the final result.

camel3 takes advantage of the built-in libraries, a regular expression is used to split the string into boxed strings, each of these is then capitalized and concatenated.

In all three functions the input is first converted to lower case.

check can be used to ensure that all the functions produce equivalent output.

alpha=: a.{~,65 97+/i.26camel=: 3 : 0y=. tolower yi=. I. (> 0,}:) b=. y e. alpha(b # toupper@(i&{) i} ]) y)isalpha=: e.&alphacapital=: (toupper@{.,}.)^:(1<:#)format =: [: ,&' ' tolowercase =: [: ; [: capital&.> ] <;._2~ [: -. isalphacamel2 =: case@formatrequire'regex text'camel3=: [: ; [: capitalize&.> [: '[a-zA-Z]+'&rxall tolowercheck=: [: ,. camel;camel2;camel3
Programming language J (2024)

FAQs

Is there a programming language called J? ›

J is a very terse array programming language, and is most suited to mathematical and statistical programming, especially when performing operations on matrices. It has also been used in extreme programming and network performance analysis.

What is software J? ›

J is a high-level, general-purpose programming language that is particularly suited to the mathematical, statistical, and logical analysis of data. It is a powerful tool for developing algorithms and exploring problems that are not already well understood.

What are the operators in the J language? ›

Operators in J are referred to as verbs. Verbs are either monadic (taking a single argument, such as *: 3 , "3 squared") or dyadic (taking two arguments, one on either side, such as 5 - 4 , "5 minus 4").

What is J in C programming? ›

i and j are just a variable name, you can use any variable name like a, b, c,x, y or number, length etc. i, j, k is probably preferred because they are short so fast to write in codes & commonly used by codes or courses we commonly see, so we also start using them.

What coding languages begin with J? ›

J
  • Java.
  • JavaScript.
  • Julia.

What is system J? ›

SystemJ is a language for designing and programming concurrent and distributed software systems.

What is the jai language? ›

Jai is a programming language developed by Jonathan Blow, who is well-known as a game designer and developer. His best known games are Braid (2008) and The Witness (2016), both written in C++.

What is JM software? ›

JM Software Services provides consulting, software development, and software support services for contact centers and operations that require shift workers. Our core staff has over 60 years of experience in providing services for forecasting, scheduling, management, and evaluation of employees in these environments.

What is J operator in quantum mechanics? ›

There are several angular momentum operators: total angular momentum (usually denoted J), orbital angular momentum (usually denoted L), and spin angular momentum (spin for short, usually denoted S).

Is there a programming language called f? ›

F is a modular, compiled, numeric programming language, designed for scientific programming and scientific computation. F was developed as a modern Fortran, thus making it a subset of Fortran 95.

What are operators in Python language? ›

Operators refer to special symbols that perform operations on values and variables. Furthermore, the operands in python, one of the programming languages, refer to the values on which the operator operates. Most noteworthy, operators can carry out arithmetic, relational, and logical operations.

What language should j learn? ›

French. French is one of the most popular languages in the world to learn. It's an official language in 29 countries and is a language of business and culture. Many native English speakers already have some level of French, as it's commonly taught in schools worldwide.

What is j in linguistics? ›

The English "j" sound is a voiced postalveolar affricate, transcribed in the International Phonetic Alphabet as /dʒ/. It is indeed the voiced counterpart to the voiceless "ch" sound /tʃ/. The phones [dʒ] and [tʃ] are both fairly common, as far as affricates go.

What is the difference between Java and J? ›

JavaScript are radically different programming languages. JavaScript is a beginner-friendly programming language that allows developers to design interactive websites. On the other hand, Java is a complex language used to build sophisticated applications like Android apps, chatbots, and financial software.

What languages start with J? ›

J
  • Jacaltec or Jakalteko (Mayan)
  • Jalaa (unclassified, possibly Niger–Congo)
  • Japanese (Japonic)
  • Jaqaru (Aymaran)
  • Jarai (Malayo-Polynesian)
  • Javanese (Malayo-Polynesian)
  • Jibbali or Shehri (Semitic)
  • Jewish Babylonian Aramaic (Aramaic)

What is the J code in Java? ›

use JCode to force frag and recompile of java code. Benefit of second option is that it is faster and more sophisticated than first one. sometime you might not even have access to make changes in code in an environment. this command will compile all java services present under Default package.

Top Articles
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 6256

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.