Partitioned Enclose

From APL Wiki
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.

In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where divisions begin:

      1 0 1 0 0 0 0'HiEarth'
┌──┬─────┐
HiEarth
└──┴─────┘
Works in: Dyalog APL

Almost all dialects restrict the left argument to provide only this functionality. However, the left argument can be interpreted as a count of how many partitions begin with a particular position:

      2 0 3 0 0 0 0'HiEarth'
┌┬──┬┬┬─────┐
││Hi│││Earth
└┴──┴┴┴─────┘

Additional trailing empty divisions are thus created by adding an additional division count corresponding to the position beyond the end of the right argument:

      1 0 1 0 0 0 0 1'HiEarth'
┌──┬─────┬┐
HiEarth││
└──┴─────┴┘

This interpretation allows a simple definition of a split-into-lengths function:

Try it online!

      Split{  ¯1 +\ ¯11,}
      3 3 4 Split 'HowAreYou?'
┌───┬───┬────┐
HowAreYou?
└───┴───┴────┘

See also

External links

Tutorials

Documentation

APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
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, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Case convertUnicode convert
Operators SearchReplace