**J**

This

**programming language**may be used to instruct a computer to perform a task.

Official website |
---|

Execution method: | Interpreted |
---|---|

Type safety: | Safe |

Type strength: | Strong (but regular) |

Type checking: | Dynamic |

Lang tag(s): | j |

See Also: |

## Contents

## The J language[edit]

J is a notational programming language designed for interactive use.

It is an array language; data is universally structured as rectangular arrays.

It is a functional language; creation and composition of functions is emphasized.

Object-module and imperative techniques are supported, but not required.

The J programming language was designed and developed by Ken Iverson and Roger Hui. It is a closely related successor to APL, also by Iverson which itself was a successor to the notation Ken Iverson used to teach his classes about computers in the 1950s.

The notation draws heavily from concepts of Abstract algebra and Tensor calculus, simplified for describing computer architecture and design to a pragmatic business audience. (The ideas themselves are simple, but for some reason the topics scare most teachers.)

## Reading J[edit]

J is meant to be read with the aid of a computer. J sentences are single lines and trying variations and simplifications of an expression is common practice. The first step in understanding any J sentence is to understand the data you started with and the data which resulted. When learning how a J sentence works, you can also try simpler sentences with the same data or perhaps related data. When trying to understand contexts that use large data structures, it can often be wise to investigate small, representative samples until you understand how the code works.

Unless you attend an institution which has made a J interpreter available to you through your web browser (or preinstalled on your machine), if you want to see how J works you should probably install a copy of J -- or you can try one of the "try me" links, below. If you want to understand how to experiment with alternative expressions you should probably also be studying some of its documentation.

For example, the phrase `(+/ % #)`

finds the average of a list of numbers.

(+/ % #) 1 2 3

2

To understand how this works, you might try working with simpler sentences and their variations.

+/ 1 2 3

6

+/4 5 6

15

# 1 2 3

3

# 2 3 4

3

6 % 3

2

15 % 3

5

(+/ % #) 4 5 6

5

By themselves, these experiments mean nothing, but if you know that +/ was finding the sum of a list and # was finding the length of a list and that % was dividing the two quantities (and looks almost like one of the old school division symbols) then these experiments might help confirm that you have understood things properly.

## Some Perspective[edit]

If you wish to use J you will also have to learn a few grammatical rules (J's parser has 9 reduction rules and "shift" and "accept" - the above examples use four of those rules). J verbs have two definitions - a single argument "monadic" definition and a two argument "dyadic" definition. These terms are borrowed from music and are distinct from Haskell's use of the word "monad". The dyadic definitions are in some sense related to LISP's "cons cell" but are implemented as grammar rather than data structure, and are a pervasive part of the language.

Another pervasive feature of the language is rank.

The language represents capabilities of hardware. For example, if language did not have an internal stack, a word's definition could not be used during the execution of that word. All current J implementations support recursion, but in some sense this is a convenience, and it's reasonable to imagine J implementations which do not (perhaps in a "compile to silicon" implementation).

## J on RosettaCode[edit]

Discussion of the goals of the J community on RC and general guidelines for presenting J solutions takes place at House Style.

## Jedi on RosettaCode[edit]

- Roger Hui: contributions, J wiki
- Tracy Harms: contributions, J wiki
- Dan Bron: contributions, J wiki
- Arie Groeneveld: contributions
- Raul Miller: contributions, J wiki
- Jose Quintana: contributions, J wiki
- Ric Sherlock: contributions, J wiki
- Avmich: contributions
- VZC: contributions
- Alex 'bathala' Rufon: contributions, J wiki
- David Lambert:contributions
- JimTheriot: contributions
- Devon McCormick: contributions

## Try me[edit]

Want to try one of those cryptic J lines you see peppered through RC? Try pasting it into this browser-based implementation of J.

If you want to be a bit more interactive, and get some guidance from J gurus, you can join the actual J IRC channel on Freenode, #jsoftware. Buubot and several other J eval bots run there. If you don't have an IRC client you can try freenode's web interface (or just give it a quick spin). More details about the J IRC community is available.

If any of that piques your interest, and you want to explore a little more, you can download J and join the J forums.

If you have problems executing any of the J code here on Rosetta, please make a note of it either on the task page itself, on the talk page, or on the appropriate J forum, whichever is best. It might be that there's a version dependency that needs to be documented, or you might have found an actual bug.

## Subcategories

This category has the following 3 subcategories, out of 3 total.

## Pages in category "J"

The following 845 pages are in this category, out of 845 total.

### A

- A+B
- ABC Problem
- Abstract type
- Abundant, deficient and perfect number classifications
- Accumulator factory
- Ackermann function
- Active object
- Add a variable to a class instance at runtime
- Address of a variable
- AKS test for primes
- Align columns
- Aliquot sequence classifications
- Almost prime
- Amb
- Amicable pairs
- Anagrams
- Anagrams/Deranged anagrams
- Animate a pendulum
- Animation
- Anonymous recursion
- Append a record to the end of a text file
- Apply a callback to an array
- Arbitrary-precision integers (included)
- Archimedean spiral
- Arena storage pool
- Arithmetic coding/As a generalized change of radix
- Arithmetic evaluation
- Arithmetic-geometric mean
- Arithmetic-geometric mean/Calculate Pi
- Arithmetic/Complex
- Arithmetic/Integer
- Arithmetic/Rational
- Array concatenation
- Array length
- Array map
- Array search
- Arrays
- ASCII art diagram converter
- Aspect Oriented Programming
- Assertions
- Assertions in design by contract
- Associative array/Creation
- Associative array/Iteration
- Average loop length
- Averages/Arithmetic mean
- Averages/Mean angle
- Averages/Mean time of day
- Averages/Median
- Averages/Mode
- Averages/Pythagorean means
- Averages/Root mean square
- Averages/Simple moving average

### B

- Babbage problem
- Bacon cipher
- Balanced brackets
- Balanced ternary
- Barnsley fern
- Base64 encode data
- Benford's law
- Bernoulli numbers
- Best shuffle
- Bilinear interpolation
- Binary digits
- Binary search
- Binary strings
- Birthday problem
- Bitmap
- Bitmap/Bresenham's line algorithm
- Bitmap/Bézier curves/Cubic
- Bitmap/Bézier curves/Quadratic
- Bitmap/Flood fill
- Bitmap/Histogram
- Bitmap/Midpoint circle algorithm
- Bitmap/Read a PPM file
- Bitmap/Write a PPM file
- Bitwise IO
- Bitwise operations
- Boolean values
- Box the compass
- Brace expansion
- Break OO privacy
- Brownian tree
- Bulls and cows
- Bulls and cows/Player

### C

- Caesar cipher
- Calculate P-Value
- Calendar
- Calendar - for "REAL" programmers
- Call a foreign-language function
- Call a function
- Call a function in a shared library
- Call an object method
- Canny edge detector
- Card shuffles
- Case-sensitivity of identifiers
- Casting out nines
- Catalan numbers
- Catalan numbers/Pascal's triangle
- Catamorphism
- Catmull–Clark subdivision surface
- Chaos game
- Character codes
- Chebyshev coefficients
- Check Machin-like formulas
- Check output device is a terminal
- Check that file exists
- Checkpoint synchronization
- Chinese remainder theorem
- Cholesky decomposition
- Cipolla's algorithm
- Circles of given radius through two points
- Classes
- Closest-pair problem
- Closures/Value capture
- Collections
- Color quantization
- Colour bars/Display
- Colour pinstripe/Display
- Combinations
- Combinations and permutations
- Combinations with repetitions
- Comma quibbling
- Command-line arguments
- Commatizing numbers
- Comments
- Compare a list of strings
- Compare sorting algorithms' performance
- Compile-time calculation
- Compound data type
- Concurrent computing
- Conditional structures
- Conjugate transpose
- Constrained genericity
- Constrained random points on a circle
- Continued fraction
- Continued fraction/Arithmetic/Construct from rational number
- Continued fraction/Arithmetic/G(matrix NG, Contined Fraction N)
- Convert decimal number to rational
- Convert seconds to compound duration
- Convex hull
- Conway's Game of Life
- Copy a string
- Count in factors
- Count in octal
- Count occurrences of a substring
- Count the coins
- Cramer's rule
- CRC-32
- Create a file
- Create a two-dimensional array at runtime
- Create an HTML table
- Create an object/Native demonstration
- CSV data manipulation
- CSV to HTML translation
- Currency
- Currying
- Cut a rectangle
- Cycle detection

### D

- User:DanBron/Game of Nim
- Date format
- Date manipulation
- Day of the week
- Deal cards for FreeCell
- Death Star
- Decimal floating point number to binary
- Decision tables
- Deconvolution/1D
- Deconvolution/2D+
- Deepcopy
- Delegates
- Delete a file
- Deming's Funnel
- Detect division by zero
- Determine if a string is numeric
- Dice game probabilities
- Digital root
- Digital root/Multiplicative digital root
- Dijkstra's algorithm
- Dinesman's multiple-dwelling problem
- Discordian date
- Display a linear combination
- DNS query
- Documentation
- Dot product
- Doubly-linked list/Definition
- Doubly-linked list/Element definition
- Doubly-linked list/Element insertion
- Doubly-linked list/Traversal
- Dragon curve
- Draw a clock
- Draw a cuboid
- Draw a sphere
- Dutch national flag problem
- Dynamic variable names

### E

- Egyptian fractions
- Element-wise operations
- Elementary cellular automaton
- Elementary cellular automaton/Infinite length
- Elementary cellular automaton/Random Number Generator
- Elliptic curve arithmetic
- Emirp primes
- Empty directory
- Empty program
- Empty string
- Enforced immutability
- Entropy
- Entropy/Narcissist
- Enumerations
- Environment variables
- Equilibrium index
- Ethiopian multiplication
- Euler method
- Euler's sum of powers conjecture
- Evaluate binomial coefficients
- Even or odd
- Evolutionary algorithm
- Exceptions
- Exceptions/Catch an exception thrown in a nested call
- Executable library
- Execute a Markov algorithm
- Execute a system command
- Execute Brain****
- Execute HQ9+
- Execute SNUSP
- Exponentiation operator
- Exponentiation order
- Extend your language
- Extensible prime generator
- Extract file extension
- Extreme floating point values

### F

- Factorial
- Factors of a Mersenne number
- Factors of an integer
- Farey sequence
- Fast Fourier transform
- FASTA format
- Faulhaber's formula
- Fibonacci n-step number sequences
- Fibonacci sequence
- Fibonacci word
- Fibonacci word/fractal
- File extension is in extensions list
- File input/output
- File modification time
- File size
- Filter
- Find common directory path
- Find first and last set bit of a long integer
- Find largest left truncatable prime in a given base
- Find limit of recursion
- Find palindromic numbers in both binary and ternary bases
- Find the last Sunday of each month
- Find the missing permutation
- First class environments
- First-class functions
- First-class functions/Use numbers analogously
- Five weekends
- FizzBuzz
- Flatten a list
- Flipping bits game
- Flow-control structures
- Floyd's triangle
- Floyd-Warshall algorithm
- Forest fire
- Fork
- Formal power series
- Formatted numeric output
- Forward difference
- Four bit adder
- Fractal tree
- Fractran
- Free polyominoes enumeration
- FTP
- Function composition
- Function definition
- Function frequency
- Function prototype
- Functional coverage tree

### G

- Galton box animation
- Gamma function
- Gaussian elimination
- General FizzBuzz
- Generalised floating point addition
- Generate Chess960 starting position
- Generate lower case ASCII alphabet
- Generate random chess position
- Generator/Exponential
- Generic swap
- Geometric algebra
- Get system command output
- Globally replace text in several files
- Go Fish
- Gray code
- Grayscale image
- Greatest common divisor
- Greatest element of a list
- Greatest subsequential sum
- Greyscale bars/Display
- Guess the number
- Guess the number/With feedback
- Guess the number/With feedback (player)
- GUI component interaction
- GUI enabling/disabling of controls

### H

- Hailstone sequence
- Hamming numbers
- Happy numbers
- Harshad or Niven series
- Hash from two arrays
- Hash join
- Haversine formula
- Hello world/Graphical
- Hello world/Line printer
- Hello world/Newbie
- Hello world/Newline omission
- Hello world/Standard error
- Hello world/Text
- Hello world/Web server
- Here document
- Heronian triangles
- Hickerson series of almost integers
- Higher-order functions
- History variables
- Hofstadter Figure-Figure sequences
- Hofstadter Q sequence
- Hofstadter-Conway $10,000 sequence
- Holidays related to Easter
- Horizontal sundial calculations
- Horner's rule for polynomial evaluation
- Host introspection
- Hostname
- Hough transform
- HTTP
- HTTPS
- Huffman coding

### I

- I before E except after C
- I.Q. Puzzle
- IBAN
- Identity matrix
- Idiomatically determine all the characters that can be used for symbols
- Idiomatically determine all the lowercase and uppercase letters
- Image convolution
- Image noise
- Implicit type conversion
- Include a file
- Increment a numerical string
- Index finite lists of positive integers
- Infinity
- Inheritance/Multiple
- Inheritance/Single
- Input loop
- Input/Output for Lines of Text
- Input/Output for Pairs of Numbers
- Integer comparison
- Integer overflow
- Integer sequence
- Interactive programming
- Introspection
- Inverted index
- Inverted syntax
- Iterated digits squaring

### K

### L

- Langton's ant
- Largest int from concatenated ints
- Last Friday of each month
- Last letter-first letter
- Leap year
- Least common multiple
- Left factorials
- Letter frequency
- Levenshtein distance
- Linear congruential generator
- Linux CPU utilization
- List comprehensions
- List rooted trees
- Literals/Floating point
- Literals/Integer
- Literals/String
- Logical operations
- Long multiplication
- Longest common prefix
- Longest common subsequence
- Longest Common Substring
- Longest increasing subsequence
- Longest string challenge
- Look-and-say sequence
- Loop over multiple arrays simultaneously
- Loops/Break
- Loops/Continue
- Loops/Do-while
- Loops/Downward for
- Loops/For
- Loops/For with a specified step
- Loops/Foreach
- Loops/Infinite
- Loops/N plus one half
- Loops/Nested
- Loops/While
- LU decomposition
- Lucas-Lehmer test
- Lucky and even lucky numbers
- Ludic numbers
- Luhn test of credit card numbers
- Lychrel numbers
- LZW compression

### M

- Mad Libs
- Magic squares of odd order
- Make directory path
- Man or boy test
- Mandelbrot set
- Map range
- Matrix arithmetic
- Matrix multiplication
- Matrix transposition
- Matrix-exponentiation operator
- Maximum triangle path sum
- Maze generation
- Maze solving
- MD5
- MD5/Implementation
- Median filter
- Memory allocation
- Memory layout of a data structure
- Menu
- Metaprogramming
- Middle three digits
- Miller–Rabin primality test
- Minesweeper game
- Modular exponentiation
- Modular inverse
- Modulinos
- Monads/List monad
- Monads/Maybe monad
- Monads/Writer monad
- Monte Carlo methods
- Monty Hall problem
- Morpion solitaire
- Morse code
- Most frequent k chars distance
- Move-to-front algorithm
- Multi-dimensional array
- Multifactorial
- Multiline shebang
- Multiple distinct objects
- Multiple regression
- Multiplication tables
- Multiplicative order
- Multisplit
- Munching squares
- Musical scale
- Mutual recursion

### N

- N'th
- N-queens problem
- Named parameters
- Names to numbers
- Naming conventions
- Narcissist
- Narcissistic decimal number
- Native shebang
- Natural sorting
- Nautical bell
- Non-continuous subsequences
- Non-decimal radices/Convert
- Non-decimal radices/Input
- Non-decimal radices/Output
- Nonoblock
- Nth root
- Null object
- Number names
- Number reversal game
- Numeric error propagation
- Numerical integration
- Numerical integration/Gauss-Legendre Quadrature

### O

### P

- Palindrome detection
- Pangram checker
- Paraffins
- Parallel calculations
- Parametric polymorphism
- Parse an IP Address
- Parse command-line arguments
- Parsing/RPN calculator algorithm
- Parsing/RPN to infix conversion
- Parsing/Shunting-yard algorithm
- Partial function application
- Particle Swarm Optimization
- Pascal matrix generation
- Pascal's triangle
- Pascal's triangle/Puzzle
- Password generator
- Pathological floating point problems
- Pattern matching
- Penney's game
- Pentagram
- Percentage difference between images
- Percolation/Mean cluster density
- Percolation/Mean run density
- Percolation/Site percolation
- Perfect numbers
- Perfect shuffle
- Perlin noise
- Permutation test
- Permutations
- Permutations by swapping
- Permutations with repetitions
- Permutations/Derangements
- Permutations/Rank of a permutation
- Pernicious numbers
- Phrase reversals
- Pi
- Pick random element
- Pig the dice game
- Pig the dice game/Player
- Pinstripe/Display
- Plasma effect
- Playfair cipher
- Playing cards
- Plot coordinate pairs
- Pointers and references
- Poker hand analyser
- Polymorphic copy
- Polymorphism
- Polynomial long division
- Polynomial regression
- Polynomial synthetic division
- Polyspiral
- Population count
- Power set
- Pragmatic directives
- Price fraction
- Primality by trial division
- Prime conspiracy
- Prime decomposition
- Primes - allocate descendants to their ancestors
- Primorial numbers
- Priority queue
- Probabilistic choice
- Problem of Apollonius
- Program name
- Program termination
- Proof
- Proper divisors
- Pythagorean triples

### R

- Ramsey's theorem
- Random number generator (device)
- Random number generator (included)
- Random numbers
- Range expansion
- Range extraction
- Ranking methods
- Rate counter
- Ray-casting algorithm
- Read a configuration file
- Read a file character by character/UTF8
- Read a file line by line
- Read a specific line from a file
- Read entire file
- Real constants and functions
- Recursive descent parser generator
- Reduced row echelon form
- Regular expressions
- Remove duplicate elements
- Remove lines from a file
- Rename a file
- Rep-string
- Repeat
- Repeat a string
- Resistor mesh
- Respond to an unknown method call
- Return multiple values
- Reverse a string
- Reverse the gender of a string
- Reverse words in a string
- Rock-paper-scissors
- Roman numerals/Decode
- Roman numerals/Encode
- Roots of a function
- Roots of a quadratic function
- Roots of unity
- Rosetta Code/Count examples
- Rosetta Code/Find unimplemented tasks
- Rosetta Code/Fix code tags
- Rosetta Code/Rank languages by popularity
- Rot-13
- RSA code
- Run-length encoding
- Runge-Kutta method
- Runtime evaluation
- Runtime evaluation/In an environment

### S

- S-Expressions
- Safe addition
- Sailors, coconuts and a monkey problem
- Same Fringe
- Scope modifiers
- Search a list
- SEDOLs
- Self-describing numbers
- Self-hosting compiler
- Self-referential sequence
- Semiprime
- Semordnilap
- Send an unknown method call
- Separate the house number from the street name
- Sequence of non-squares
- Sequence of primes by Trial Division
- Sequence of primorial primes
- Set
- Set consolidation
- Set of real numbers
- Set puzzle
- Seven-sided dice from five-sided dice
- SHA-1
- Shell one-liner
- Short-circuit evaluation
- Show the epoch
- Sierpinski carpet
- Sierpinski triangle
- Sierpinski triangle/Graphical
- Sieve of Eratosthenes
- Simple database
- Simple windowed application
- Simulated annealing
- Singleton
- Singly-linked list/Element definition
- Singly-linked list/Element insertion
- Singly-linked list/Traversal
- Sleep
- Smith numbers
- Sockets
- Solve a Holy Knight's tour
- Solve the no connection puzzle
- Sort an array of composite structures
- Sort an integer array
- Sort disjoint sublist
- Sort stability
- Sort using a custom comparator
- Sorting algorithms/Bead sort
- Sorting algorithms/Bogosort
- Sorting algorithms/Bubble sort
- Sorting Algorithms/Circle Sort
- Sorting algorithms/Cocktail sort
- Sorting algorithms/Comb sort
- Sorting algorithms/Counting sort
- Sorting algorithms/Cycle sort
- Sorting algorithms/Gnome sort
- Sorting algorithms/Heapsort
- Sorting algorithms/Insertion sort
- Sorting algorithms/Merge sort
- Sorting algorithms/Pancake sort
- Sorting algorithms/Patience sort
- Sorting algorithms/Permutation sort
- Sorting algorithms/Quicksort
- Sorting algorithms/Radix sort
- Sorting algorithms/Selection sort
- Sorting algorithms/Shell sort
- Sorting algorithms/Stooge sort
- Sorting algorithms/Strand sort
- Sorting algorithms/Tree sort on a linked list
- Soundex
- Sparkline in unicode
- Special characters
- Special variables
- Spiral matrix
- Stable marriage problem
- Stack
- Stack traces
- Stair-climbing puzzle
- Standard deviation
- Start from a main routine
- State name puzzle
- Statistics/Basic
- Statistics/Normal distribution
- Stem-and-leaf plot
- Stern-Brocot sequence
- Straddling checkerboard
- String append
- String case
- String comparison
- String concatenation
- String interpolation (included)
- String length
- String matching
- String prepend
- Strip a set of characters from a string
- Strip block comments
- Strip comments from a string
- Strip control codes and extended characters from a string
- Strip whitespace from a string/Top and tail
- Subleq
- Subset sum problem
- Substitution Cipher
- Substring
- Substring/Top and tail
- Subtractive generator
- Sudoku
- Suffix tree
- Sum and product of an array
- Sum digits of an integer
- Sum multiples of 3 and 5
- Sum of a series
- Sum of squares
- Superellipse
- Superpermutation minimisation
- Sutherland-Hodgman polygon clipping
- Symmetric difference
- Synchronous concurrency
- System time

### T

- Table creation
- Table creation/Postal addresses
- Take notes on the command line
- Taxicab numbers
- Temperature conversion
- Terminal control/Clear the screen
- Terminal control/Coloured text
- Terminal control/Cursor positioning
- Terminal control/Dimensions
- Terminal control/Display an extended character
- Terminal control/Hiding the cursor
- Terminal control/Inverse video
- Terminal control/Ringing the terminal bell
- Ternary logic
- Test a function
- Test integerness
- Text processing/1
- Text processing/2
- Text processing/Max licenses in use
- Textonyms
- The Twelve Days of Christmas
- Thiele's interpolation formula
- Thue-Morse
- Tic-tac-toe
- Time a function
- Tokenize a string
- Tokenize a string with escaping
- Tonelli-Shanks algorithm
- Top rank per group
- Topic variable
- Topological sort
- Topological sort/Extracted top item
- Topswops
- Total circles area
- Towers of Hanoi
- Trabb Pardo–Knuth algorithm
- Tree traversal
- Trigonometric functions
- Truncatable primes
- Truncate a file
- Truth table
- Twelve statements
- Type detection

### U

- Ulam spiral (for primes)
- Unbias a random generator
- Undefined values
- Unicode strings
- Unicode variable names
- Universal Turing machine
- Unix/ls
- Untrusted environment
- Update a configuration file
- URL decoding
- URL encoding
- URL parser
- Use another language to call a function
- User defined pipe and redirection operators
- User input/Graphical
- User input/Text

### V

- Validate International Securities Identification Number
- Vampire number
- Van der Corput sequence
- Variable size/Get
- Variable size/Set
- Variable-length quantity
- Variables
- Variadic function
- Vector
- Vector products
- Verify distribution uniformity/Chi-squared test
- Verify distribution uniformity/Naive
- Vigenère cipher
- Visualize a tree
- Vogel's approximation method
- Voronoi diagram

### W

- Pages using duplicate arguments in template calls
- Execution method/Interpreted
- Typing/Safe
- Typing/Strong (but regular)
- Typing/Checking/Dynamic
- Programming Languages
- Programming paradigm/Dynamic
- Programming paradigm/Functional
- Programming paradigm/Imperative
- Programming paradigm/Procedural
- Programming paradigm/Reflective
- Programming paradigm/Tacit