Get the code: learnapl.apl
โ Comments in APL are prefixed by โ.
โ A list of numbers. (ยฏ is negative)
2 3e7 ยฏ4 50.3
โ An expression, showing some functions. In APL, there's
โ no order of operations: everything is parsed right-to-
โ left. This is equal to 5 + (4 ร (2 รท (5 - 3))) = 9:
5 + 4 ร 2 รท 5 - 3 โ 9
โ These functions work on lists, too:
1 2 3 4 ร 5 โ 5 10 15 20
1 2 3 4 ร 5 6 7 8 โ 5 12 21 32
โ All functions have single-argument and dual-argument
โ meanings. For example, "ร" applied to two arguments
โ means multiply, but when applied to only a right-hand
โ side, it returns the sign:
ร ยฏ4 ยฏ2 0 2 4 โ ยฏ1 ยฏ1 0 1 1
โ Values can be compared using these operators (1 means
โ "true", 0 means "false"):
10 20 30 = 10 20 99 โ 1 1 0
10 20 30 < 10 20 99 โ 0 0 1
โ "โณn" returns a vector containing the first n naturals.
โ Matrices can be constructed using โด (reshape):
4 3 โด โณ5 โ 0 1 2
โ 3 4 0
โ 1 2 3
โ 4 0 1
โ Single-argument โด gives you the dimensions back:
โด 4 3 โด โณ5 โ 4 3
โ Values can be stored using โ. Let's calculate the mean
โ value of a vector of numbers:
A โ 10 60 55 23
โ Sum of elements of A (/ is reduce):
+/A โ 148
โ Length of A:
โดA โ 4
โ Mean:
(+/A) รท (โดA) โ 37
โ We can define this as a function using {} and โต:
mean โ {(+/โต)รทโดโต}
mean A โ 37
Got a suggestion? A correction, perhaps? Open an Issue on the GitHub Repo, or make a pull request yourself!
Originally contributed by nooodl, and updated by 4 contributors.