Simple examples: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
No edit summary
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.
==Text processing==
APL represents text as character lists (vectors), making many text operations trivial.
=== Indices of multiple elements ===
=== 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:
<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>
<pre class=apl>

Revision as of 15:25, 10 October 2019

This page will contain examples that serve well to show APL's strength. They require minimal background and have no special dependencies.

Text processing

APL represents text as character lists (vectors), making many text operations trivial.

Indices of multiple elements

gives us a mask for elements (characters) in the left argument that are members of the right argument:

      'mississippi'∊'sp'
0 0 1 1 0 1 1 0 1 1 0

gives us the indices where true (1):

      ⍸'mississippi'∊'sp'
3 4 6 7 9 10

We can combine this into an anonymous infix (dyadic) function:

      'mississippi' (⍸∊) 'sp'
3 4 6 7 9 10

Parenthesis nesting level

      +\-⌿'()'∘.='plus(square(a),plus(square(b),times(2,plus(a,b)))'
0 0 0 0 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 3 2 1

Template:APL programming language