Partitioned Enclose: Difference between revisions
mNo edit summary |
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 | {{Built-in|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 <ref group=note name=max></ref> '''divisions''' begin: | |||
<source lang=apl> | <source lang=apl> | ||
1 0 1 0 0 0 0⊂'HiEarth' | 1 0 1 0 0 0 0⊂'HiEarth' | ||
Line 9: | Line 9: | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]]}} | {{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: | |||
<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 16: | ||
└┴──┴┴┴─────┘ | └┴──┴┴┴─────┘ | ||
</source> | </source> | ||
Additional trailing empty divisions are created by adding an additional division count corresponding to the index beyond the end of the right argument<ref group=note name=not></ref>: | Additional trailing empty divisions are thus created by adding an additional division count corresponding to the index beyond the end of the right argument<ref group=note name=not></ref>: | ||
<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 23: | ||
└──┴─────┴┘ | └──┴─────┴┘ | ||
</source> | </source> | ||
This interpretation allows 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 34: | Line 34: | ||
</source> | </source> | ||
{{Works in|[[Extended Dyalog APL]]}} | {{Works in|[[Extended Dyalog APL]]}} | ||
==External links== | ==External links== | ||
===Tutorials=== | ===Tutorials=== |
Revision as of 13:00, 27 January 2020
⊂
|
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 [note 1] divisions begin:
1 0 1 0 0 0 0⊂'HiEarth' ┌──┬─────┐ │Hi│Earth│ └──┴─────┘
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 index beyond the end of the right argument[note 2]:
1 0 1 0 0 0 0 1⊂'HiEarth' ┌──┬─────┬┐ │Hi│Earth││ └──┴─────┴┘
This interpretation allows a simple definition of a split-into-lengths function:
Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺} 3 3 4 Split 'HowAreYou?' ┌───┬───┬────┐ │How│Are│You?│ └───┴───┴────┘
External links
Tutorials
Documentation
Cite error: <ref>
tags exist for a group named "note", but no corresponding <references group="note"/>
tag was found