APL

Личный сайт Go-разработчика из Казани

1⍝ Comments in APL are prefixed by ⍝. 2 3⍝ A list of numbers. (¯ is negative) 42 3e7 ¯4 50.3 5 6⍝ An expression, showing some functions. In APL, there's 7⍝ no order of operations: everything is parsed right-to- 8⍝ left. This is equal to 5 + (4 × (2 ÷ (5 - 3))) = 9: 95 + 4 × 2 ÷ 5 - 3 ⍝ 9 10 11⍝ These functions work on lists, too: 121 2 3 4 × 5 ⍝ 5 10 15 20 131 2 3 4 × 5 6 7 8 ⍝ 5 12 21 32 14 15⍝ All functions have single-argument and dual-argument 16⍝ meanings. For example, "×" applied to two arguments 17⍝ means multiply, but when applied to only a right-hand 18⍝ side, it returns the sign: 19 20× ¯4 ¯2 0 2 4 ⍝ ¯1 ¯1 0 1 1 21 22⍝ Values can be compared using these operators (1 means 23⍝ "true", 0 means "false"): 24 2510 20 30 = 10 20 99 ⍝ 1 1 0 26 2710 20 30 < 10 20 99 ⍝ 0 0 1 28 29⍝ "⍳n" returns a vector containing the first n naturals. 30⍝ Matrices can be constructed using ⍴ (reshape): 314 3 5 ⍝ 0 1 2 32 ⍝ 3 4 0 33 ⍝ 1 2 3 34 ⍝ 4 0 1 35 36⍝ Single-argument ⍴ gives you the dimensions back: 37 4 3 5 ⍝ 4 3 38 39⍝ Values can be stored using ←. Let's calculate the mean 40⍝ value of a vector of numbers: 41A 10 60 55 23 42 43⍝ Sum of elements of A (/ is reduce): 44+/A ⍝ 148 45 46⍝ Length of A: 47A ⍝ 4 48 49⍝ Mean: 50(+/A) ÷ (A) ⍝ 37 51 52⍝ We can define this as a function using {} and ⍵: 53mean {(+/⍵)÷⍴} 54mean A ⍝ 37

Further Reading