J concepts in SC:
Guides | Language

J concepts in SC

An overview of concepts borrowed from J

The J programming language is a successor of APL (see http://www.jsoftware.com). These languages are made for processing arrays of data and are able to express complex notions of iteration implicitly.

The following are some concepts borrowed from or inspired by J. Thinking about multidimensional arrays can be both mind bending and mind expanding. It may take some effort to grasp what is happening in these examples.

Filling arrays

iota fills an array with a counter

fill a multidimensional array

Creating arrays

using dup to create arrays

! is an abbreviation of dup

other ways to do the same thing:

Operator adverbs

Adverbs are a third argument passed to binary operators that modifies how they iterate over SequenceableCollections or Streams. See the Adverbs for Binary Operators help file for more information.

Operator depth

J has a concept called verb rank, which is probably too complex to understand and implement in SC, but operator depth is similar and simpler. A binary operator can be given a depth at which to operate. Negative depths iterate the opposite operand. These are better understood by example. It is not currently possible to combine adverb and depth.


deepCollect operates a function at different dimensions or depths in an array.

Sections of multidimensional arrays

slice can get sections of multidimensional arrays. nil gets all the indices of a dimension.

Sorting order

generate a random array:

order returns an array of indices representing what would be the sorted order of the array:

calling order on the order returns an array of indices that returns the sorted array to the original scrambled order:


bubbling wraps an item in an array of one element. it takes the depth and levels as arguments.

similarly, unbubble unwraps an Array if it contains a single element.

Laminating with the +++ operator

the +++ operator takes each item from the second list and appends it to the corresponding item in the first list. If the second list is shorter, it wraps.


reshapeLike allows you to make one nested array be restructured in the same manner as another.

If the lengths are different, the default behaviour is to wrap:

but you can specify other index operators:

measuring dimensionality and size

maxSizeAtDepth allows you to check the maximum array size at a given depth dimension

inverting dimensions

flopDeep allows you to to invert the outermost dimension with a dimension at any depth. This is analogous to flop, which does the same for 2-dimensional arrays.


allTuples will generate all combinations of the sub arrays