Partition: Difference between revisions

Jump to navigation Jump to search
45 bytes added ,  21:35, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 1: Line 1:
{{Built-ins|Partition|⊆|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the non-negative integer left argument. This article uses <source lang=apl inline>⊆</source> to distinguish Partition from [[Partitioned Enclose]] (which is always <source lang=apl inline>⊂</source>), but the actual [[glyph]] used [[Migration level|varies by dialect]].
{{Built-ins|Partition|⊆|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the non-negative integer left argument. This article uses <source lang=apl inline>⊆</syntaxhighlight> to distinguish Partition from [[Partitioned Enclose]] (which is always <source lang=apl inline>⊂</syntaxhighlight>), but the actual [[glyph]] used [[Migration level|varies by dialect]].


On a vector right argument, the arguments must have the same length with each element in the left argument corresponding to an element in the right argument. Partition begins a new '''division''' of its right argument whenever a left argument element is greater than its neighbour on the left (with a 0 assumed to the left of the first element):
On a vector right argument, the arguments must have the same length with each element in the left argument corresponding to an element in the right argument. Partition begins a new '''division''' of its right argument whenever a left argument element is greater than its neighbour on the left (with a 0 assumed to the left of the first element):
Line 9: Line 9:
│Hi│Earth│
│Hi│Earth│
└──┴─────┘
└──┴─────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
Right argument elements can be skipped by having their corresponding left argument element be 0:
Right argument elements can be skipped by having their corresponding left argument element be 0:
Line 17: Line 17:
│Hi│Ear│
│Hi│Ear│
└──┴───┘
└──┴───┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
In the case where the left argument is [[Boolean]], Partition splits its right argument on runs of 0s in the left argument, allowing a very short split-on-delimiter function:
In the case where the left argument is [[Boolean]], Partition splits its right argument on runs of 0s in the left argument, allowing a very short split-on-delimiter function:
Line 31: Line 31:
│How│are│you?│
│How│are│you?│
└───┴───┴────┘
└───┴───┴────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
== See also ==
== See also ==

Navigation menu