From APL Wiki
Jump to navigation Jump to search

Variant (, ⎕OPT) or Custom (: in A Dictionary of APL[1]) and Fit in J, is a special dyadic operator which takes a function as its left operand and modifies its behaviour as specified by the array right operand.

Since was not in Dyalog's atomic vector when the feature was added, a system operator alternative was provided in form of ⎕OPT.


Variant dates back all the way to Iverson notation where a subscript was used to indicate which index origin a primitive would operate under. This system was dropped in APL\360. Instead, the system command )ORIGIN was provided for controlling the interpreter's global setting. This was then supplemented with a system variable to control the global state. Though this feature is still present in many APL systems, together with numerous other system variables for controlling other aspects of the system, for example comparison tolerance, these global settings were recognised as an unfortunate design in that every programmer would be forced to set and localise every system variable that could affect the given code. Later, Ken Iverson envisioned a return to a per-invocation setting, similar to the original notation, but this time in the form of a dyadic operator that would customise primitive functions.

Although SHARP APL didn't implement Iverson's idea, J did. Later Dyalog APL 13.0 (2011) repurposed it as a way of providing auxiliary arguments to primitive and system functions, and functions derived from primitive and system operators, however its only current use in connection with primitives is to provide language settings for the Format Date-time I-beam (1200).[2]


The Dyalog system operator ⎕S takes as operands text to be searched for, and what to return for each match (with & meaning the matched text):

Works in: Dyalog APL

Only one match is found, because ⎕S defaults to being case sensitive and disallow overlapping matches. The variant operator can be used to enable case insensitivity:

 Abra  abra
Works in: Dyalog APL

This usage with a simple scalar right operand is in line with Iverson's design:

   1 = 1+1e_14         NB. equivalent to 1 =  1+1e¯14 in Dictionary APL
   1 (= !. 0) 1+1e_14  NB. equivalent to 1 (= : 0) 1+1e¯14 in Dictionary APL
Works in: J

However, Dyalog also allows a name–value pair, or a vector of name–value pairs. The above example can be spelled using the IC (for Ignore Case) setting name:

 Abra  abra
Works in: Dyalog APL

Multiple settings can either be specified with multiple applications of variant, or by using a vector of name–value pairs. Here, OM (for Overlapping Matches) is enabled in addition to IC:

 Abra  abra  abra 
 Abra  abra  abra
Works in: Dyalog APL

External links




  1. Ken Iverson. A Dictionary of APL. Custom. APL Quote Quad, Volume 18, Number 1, 1987-09.
  2. Dyalog Ltd. Language Reference Guide: Format Date-time.

APL built-ins [edit]
Primitive functions
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Name classCase convertUnicode convert
Operators SearchReplace