Partitioned Enclose

From APL Wiki
Revision as of 21:40, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search

Partitioned Enclose () is a dyadic function which splits its right argument into differently sized pieces as determined by the left argument.

Basic functionality

In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where divisions begin: <syntaxhighlight lang=apl>

     1 0 1 0 0 0 0⊂'HiEarth'

┌──┬─────┐ │Hi│Earth│ └──┴─────┘ </source>

Non-Boolean left argument

Almost all dialects restrict the left argument to provide only the above functionality. However, the left argument can be interpreted as a count of how many partitions begin with a particular position: <syntaxhighlight lang=apl>

     2 0 3 0 0 0 0⊂'HiEarth'

┌┬──┬┬┬─────┐ ││Hi│││Earth│ └┴──┴┴┴─────┘ </source>

Short left argument

The dialects that support this extension also allow omission of trailing zeros, which is useful if the partitioning vector is generated by where's inverse: <syntaxhighlight lang=apl>

     ⍸⍣¯1⊢1 1 3 3 3

2 0 3

     2 0 3⊂'HiEarth'

┌┬──┬┬┬─────┐ ││Hi│││Earth│ └┴──┴┴┴─────┘ </source>

Long left argument

Additional trailing empty divisions are created by adding an additional division count corresponding to the position beyond the end of the right argument: <syntaxhighlight lang=apl>

     1 0 1 0 0 0 0 1⊂'HiEarth'

┌──┬─────┬┐ │Hi│Earth││ └──┴─────┴┘ </source>

Split into lengths

This above extensions allow a simple definition of a split-into-lengths function:

Try it online! <syntaxhighlight lang=apl>

     Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺}
     3 3 4 Split 'HowAreYou?'

┌───┬───┬────┐ │How│Are│You?│ └───┴───┴────┘ </source>

See also

External links

Tutorials

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector