Simple examples: Difference between revisions

Jump to navigation Jump to search
100 bytes removed ,  16:19, 20 November 2019
Miraheze>Adám Brudzewsky
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This page contains examples that show APL's strengths. The examples require minimal background and have no special dependencies.
This page contains examples that show APL's strengths. The examples require minimal background and have no special dependencies. If these examples are too simple for you, have a look at our [[advanced examples]].
 
== Longer examples ==
A list of more involved examples.
[[Category: Lists]]
 
* [[APL Wiki logo]]
 
* [[Convex Hull]]
 
* [[Conway's Game of Life]]
 
* [[Ranking poker hands]]


== Arithmetic mean ==
== Arithmetic mean ==
Line 40: Line 28:
will transform a list of strings representing words into a comma-separated list:
will transform a list of strings representing words into a comma-separated list:
<source lang=apl>
<source lang=apl>
    {⍺,', ',⍵}⌿'cow' 'sheep' 'cat' 'dog'
      {⍺,', ',⍵}⌿'cow' 'sheep' 'cat' 'dog'
┌────────────────────┐
┌────────────────────┐
│cow, sheep, cat, dog│
│cow, sheep, cat, dog│
Line 52: Line 40:


=== Tacit programming ===
=== Tacit programming ===
{{Main|Tacit}}


In APL’s tacit definition, no braces are needed to mark the definition of a function: primitive functions just combine in a way that enables us to omit any reference to the function arguments — hence ''tacit''. Here is the same calculation written tacitly:
In APL’s tacit definition, no braces are needed to mark the definition of a function: primitive functions just combine in a way that enables us to omit any reference to the function arguments — hence ''tacit''. Here is the same calculation written tacitly:
Line 59: Line 49:
</source>
</source>


The operator <source lang=apl inline>/</source> can also be used to modify the <source lang=apl inline>(+⌿÷≢)</source> function to produce a moving average.
The operator <source lang=apl inline></source> can also be used to modify the <source lang=apl inline>(+⌿÷≢)</source> function to produce a moving average.
<source lang=apl>
<source lang=apl>
       2 (+⌿÷≢)/ 3 4.5 7 21
       2 (+⌿÷≢)/ 3 4.5 7 21
Line 69: Line 59:
       ave 3 4.5 7 21
       ave 3 4.5 7 21
8.875
8.875
       mave ← ave/
       mave ← ave⌿
       2 mave 3 4.5 7 21
       2 mave 3 4.5 7 21
3.75 5.75 14
3.75 5.75 14
Line 143: Line 133:


=== Grille cypher ===
=== Grille cypher ===
A [https://en.wikipedia.org/wiki/Grille_(cryptography) grille] is a 500 year old method for encrypting messages.
A [[wikipedia:grille (cryptography)|grille]] is a 500 year old method for encrypting messages.
[[File:Grille.png|none|500px|frameless|left|The application of a grille cypher]]
[[File:Grille.png|none|500px|frameless|The application of a grille cypher]]
<p>
<p>
Represent both the grid of letters and the grille as character matrices.
Represent both the grid of letters and the grille as character matrices.
Line 169: Line 159:
</source>
</source>


{{APL programming language}}
{{APL development}}

Navigation menu