Simple examples: Difference between revisions
Jump to navigation
Jump to search
→Text processing
Miraheze>Adám Brudzewsky No edit summary |
Miraheze>Adám Brudzewsky |
||
Line 7: | Line 7: | ||
==Text processing== | ==Text processing== | ||
APL represents text as character lists (vectors), making many text operations trivial. | APL represents text as character lists (vectors), making many text operations trivial. | ||
=== Split text by delimiter === | |||
<source lang=apl inline>≠</source> gives 1 for true and 0 for false. It [[scalar function|pairs up]] a single element argument with all the elements of the other arguments: | |||
<source lang=apl> | |||
','≠'comma,delimited,text' | |||
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 | |||
</source> | |||
<source lang=apl inline>⊢</source> returns its right argument: | |||
<source lang=apl> | |||
','⊢'comma,delimited,text' | |||
comma,delimited,text | |||
</source> | |||
<source lang=apl inline>⊆</source> returns a list of runs as indicated by runs of 1s, leaving out elements indicated by 0s: | |||
<source lang=apl> | |||
1 1 0 1 1 1⊆'Hello!' | |||
┌──┬───┐ | |||
│He│lo!│ | |||
└──┴───┘ | |||
</source> | |||
We use the comparison [[vector]] to [[partition]] the right argument: | |||
[https://tryapl.org/?a=%27%2C%27%28%u2260%u2286%u22A2%29%27comma%2Cdelimited%2Ctext%27&run Try it now!] | |||
<source lang=apl> | |||
','(≠⊆⊢)'comma,delimited,text' | |||
┌─────┬─────────┬────┐ | |||
│comma│delimited│text│ | |||
└─────┴─────────┴────┘ | |||
</source> | |||
{{Works in|[[Dyalog APL]]}} | |||
Notice of you can read the [[tacit]] function <source lang=apl inline>≠⊆⊢</source> like an English sentence: ''The inequality partitions the right argument''. | |||
=== Indices of multiple elements === | === Indices of multiple elements === | ||
<source lang=apl inline>∊</source> gives us a mask for elements (characters) in the left argument that are members of the right argument: | <source lang=apl inline>∊</source> gives us a mask for elements (characters) in the left argument that are members of the right argument: |