Mix

Mix ( or   in nested APLs; Disclose or Open   in flat array languages) is a primitive monadic function which reduces the depth of its argument by combining all its element arrays into a single array. The shape of its result is then the shape of the argument followed by the common shape of the argument elements. Depending on the definition of Mix, the elements may be required to share the same shape, or they may be extended in shape (with fill elements) or rank to fit a common shape. In all APLs Mix allows a simple array argument, and returns it unchanged. Mix is a left inverse to both Enclose and Split, while the function First, which is identical to Mix on scalars, is a left inverse to Enclose only.

Examples
Example application, to find the longest common prefix:

History
Early experiments in array nesting usually defined a primitive to extract the contents of a nested scalar, but did not always specify how it should behave on an array. Jim Brown's "A Generalization of APL", which would become APL2, defined such a primitive, "reveal", while stating that it "may be undefined" on non-scalar arrays.

Mix was first introduced by NARS in 1981. It required all elements to have matching shape, and allowed a specified axis to define where in the result array their axes would be placed. In the same year, SHARP APL introduced the concept of a boxed array, along with the function Disclose. In SHARP, Disclose was simply defined to be the inverse of Enclose, but given function rank 0 so that it would disclose each box in an argument and combine the results. Based on SHARP's definition of Rank, the arrays to be combined were required to have the same shape, and because of its flat array model, they also had to have the same type (numeric, character, or boxed), as otherwise the result array would not be representable.

APL2, released in 1984, used the same name Disclose as SHARP APL but introduced the glyph Right Shoe. It shared NARS's function axis definition, but extended the function to allow argument elements with different shapes as long as they had the same rank. Arrays with different shapes would be padded using fill elements as with Take to bring them to a common shape large enough to contain every element.

A further extension was introduced as a consequence of J's definition of the Rank operator. In J, result arrays in a function applied with rank can have different ranks, and results with lower rank are brought to a common rank by adding leading 1s to the shape. This change was taken up by Dyalog APL in version 14.0, which introduced Rank following J's definition, in order to make Mix and Rank consistent. However, Dyalog differs from J in that it permits mixed arrays, so while in J an array containing a mix of numbers, characters, and boxes cannot be mixed, in Dyalog any array at all can be mixed.

Language support
Mix is only available in languages which allow nesting, either by boxes or nested arrays, so it is not present in early APLs such as APL\360 and APL.SV.

Lessons

 * APL Cultivation

Documentation

 * Dyalog
 * APLX
 * J dictionary, NuVoc
 * BQN