Partitioned Enclose: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the non-negative integer<ref group=note name=max>Most dialects restrict this number to a maximum of 1.</ref> left argument. | {{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the non-negative integer<ref group=note name=max>Most dialects restrict this number to a maximum of 1.</ref> left argument. | ||
On a vector right argument, the corresponding element in the left argument | On a vector right argument, the corresponding element in the left argument indicates how many<ref group=note name=max></ref> '''divisions''' to begin there: | ||
<source lang=apl> | <source lang=apl> | ||
1 0 1 0 0 0 0⊂'HiEarth' | 1 0 1 0 0 0 0⊂'HiEarth' |
Revision as of 11:59, 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││ └──┴─────┴┘
Partition allows a simple definition[note 3] of a split-into-lengths function:
Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺} 3 3 4 Split 'HowAreYou?' ┌───┬───┬────┐ │How│Are│You?│ └───┴───┴────┘
Works in: Extended Dyalog APL