Simple examples: Difference between revisions
Jump to navigation
Jump to search
no edit summary
Miraheze>Adám Brudzewsky |
Miraheze>Adám Brudzewsky No edit summary |
||
Line 1: | Line 1: | ||
This page will contain examples that serve well to show APL's strength. They require minimal background and have no special dependencies. | This page will contain examples that serve well to show APL's strength. They require minimal background and have no special dependencies. | ||
=== Indices of multiple elements === | |||
APL represents text as character lists (vectors), making many text operations trivial: | |||
<code class="apl">∊</code> gives us a mask for elements (characters) in the left argument that are members of the right argument: | |||
<pre class=apl> | |||
'mississippi'∊'sp' | |||
0 0 1 1 0 1 1 0 1 1 0 | |||
</pre> | |||
<code class="apl">⍸</code> gives us the indices where true (1): | |||
<pre class=apl> | |||
⍸'mississippi'∊'sp' | |||
3 4 6 7 9 10 | |||
</pre> | |||
We can combine this into an anonymous infix (dyadic) function: | |||
<pre class=apl> | |||
'mississippi' (⍸∊) 'sp' | |||
3 4 6 7 9 10 | |||
</pre> | |||
=== Parenthesis nesting level === | === Parenthesis nesting level === | ||
<pre class=apl> | <pre class=apl> | ||
Line 6: | Line 23: | ||
</pre> | </pre> | ||
{{APL programming language}} | {{APL programming language}} | ||