Partitioned Enclose: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 23: Line 23:
└──┴─────┴┘
└──┴─────┴┘
</source>
</source>
Partition allows a simple definition<ref group=note>In dialects that implement the full functionality of Partitioned Enclose.</ref> of a split-into-lengths function:
Partitioned Enclose allows a simple definition<ref group=note>In dialects that implement the full functionality of Partitioned Enclose.</ref> of a split-into-lengths function:


[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v/ggpzMEpAjHvVuVXjU1fSod4XCo94dj3oXH1pvqKAdowCkHrVNNtQB2ff/v7GCsYKJAliTgrpHfrljUWpkfqm9OgA Try it online!]
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qLdP/VHf1GBXvZRHbROqNQxtH3UufNS7S/NRx/JHvWvAnC1AvhVQEVABkJWSVqJg8Ki7BSKQkllcABSshQgAjdEAUuHB6uquZal5JerqGurqwanFxZn5eQFFmSABBXX1FHV1zUddi4EKnSOBvLS8YqCA@v/ggpzMEpAjHvVuVXjU1fSod4XCo94dj3oXH1pvqKAdowCkHrVNNtQB2ff/v7GCsYKJAliTgrpHfrljUWpkfqm9OgA Try it online!]

Revision as of 12:00, 27 January 2020

Partitioned Enclose () is a dyadic function which splits its right argument into differently sized pieces as determined by the non-negative integer[note 1] left argument.

On a vector right argument, the corresponding element in the left argument indicates how many[note 1] divisions to begin there:

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

Empty divisions can be inserted by beginning more than 1 division at a particular index[note 2]:

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

Additional trailing empty divisions are created by adding an additional division count corresponding to the index beyond the end of the right argument[note 2]:

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

Partitioned Enclose allows a simple definition[note 3] of a split-into-lengths function:

Try it online!

      Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺}
      3 3 4 Split 'HowAreYou?'
┌───┬───┬────┐
│How│Are│You?│
└───┴───┴────┘

Notes

  1. 1.0 1.1 Most dialects restrict this number to a maximum of 1.
  2. 2.0 2.1 Most dialects do not support this.
  3. In dialects that implement the full functionality of Partitioned Enclose.

External links

Tutorials

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
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 axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector