Simple examples

This page contains examples that show APL's strengths. The examples require minimal background and have no special dependencies.

More involved examples include:


 * Ranking poker hands

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

Split text by delimiter
gives 1 for true and 0 for false. It pairs up a single element argument with all the elements of the other arguments: returns its right argument: returns a list of runs as indicated by runs of 1s, leaving out elements indicated by 0s: We use the comparison vector to partition the right argument:

Try it now!

Notice of you can read the tacit function  like an English sentence: The inequality partitions the right argument.

Indices of multiple elements
gives us a mask for elements (characters) in the left argument that are members of the right argument: gives us the indices where true (1): We can combine this into an anonymous infix (dyadic) function:

Parenthesis nesting level
First we compare all characters to the opening and closing characters; An opening increases the current level, while a closing decreases, so we convert this to changes (or deltas) by subtracting the bottom row from the top row: The running sum is what we're looking for: