4,494
edits
No 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 left argument. | {{Built-in|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: | In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where '''divisions''' begin: | ||
<source lang=apl> | <source lang=apl> | ||
Line 8: | Line 8: | ||
└──┴─────┘ | └──┴─────┘ | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]], [[Extended Dyalog APL]]}} | ||
Almost all dialects restrict the left argument to provide only | == 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: | |||
<source lang=apl> | <source lang=apl> | ||
2 0 3 0 0 0 0⊂'HiEarth' | 2 0 3 0 0 0 0⊂'HiEarth' | ||
Line 16: | Line 17: | ||
└┴──┴┴┴─────┘ | └┴──┴┴┴─────┘ | ||
</source> | </source> | ||
Additional trailing empty divisions are | == 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 [[indices#Inverse|where's inverse]]: | |||
<source 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: | |||
<source lang=apl> | <source lang=apl> | ||
1 0 1 0 0 0 0 1⊂'HiEarth' | 1 0 1 0 0 0 0 1⊂'HiEarth' | ||
Line 23: | Line 35: | ||
└──┴─────┴┘ | └──┴─────┴┘ | ||
</source> | </source> | ||
This | == Split into lengths == | ||
This above extensions allow a simple definition 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!] | ||
Line 33: | Line 46: | ||
└───┴───┴────┘ | └───┴───┴────┘ | ||
</source> | </source> | ||
== See also == | == See also == | ||
* [[Partition]] | * [[Partition]] |