4,494
edits
(greek alpha and omega → apl alpha and omega (regular greek letters return a syntax error in Dyalog APL)) |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 35: | Line 35: | ||
So back to our mean example. <source lang=apl inline>(+⌿⍵)</source> gives the sum of the list, which is then divided by <source lang=apl inline>≢⍵</source>, the number elements in it. | So back to our mean example. <source lang=apl inline>(+⌿⍵)</source> gives the sum of the list, which is then divided by <source lang=apl inline>≢⍵</source>, the number elements in it. | ||
<source lang=apl> | <source lang=apl> | ||
{(+ | {(+⌿⍵)÷≢⍵} 3 4.5 7 21 | ||
8.875 | 8.875 | ||
</source> | </source> | ||
Line 41: | Line 41: | ||
=== Tacit programming === | === Tacit programming === | ||
{{Main|Tacit}} | {{Main|Tacit programming}} | ||
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 49: | Line 49: | ||
</source> | </source> | ||
This is a so called 3-train, also known as a ''fork''. It is evaluated like this: | |||
<source lang=apl> | {| | ||
|<source lang=apl>(+⌿ ÷ ≢) 3 4.5 7 21</source>|| {{←→}} ||<source lang=apl>(+⌿ 3 4.5 7 21) ÷ (≢ 3 4.5 7 21)</source> | |||
3. | |} | ||
</source> | |||
Note that <source lang=apl inline>+⌿</source> is evaluated as a single derived function. | |||
<source lang=apl> | The general scheme for monadic 3-trains is the following: | ||
{| | |||
|<source lang=apl>(f g h) ⍵</source>|| {{←→}} ||<source lang=apl>(f ⍵) g (h ⍵)</source> | |||
|} | |||
But other types of [[Tacit programming#Trains|trains]] are also possible. | |||
</source> | |||
==Text processing== | ==Text processing== | ||
Line 94: | Line 92: | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]]}} | ||
Notice | Notice that you can read the [[tacit]] function <source lang=apl inline>≠⊆⊢</source> like an English sentence: ''The inequality partitions the right argument''. | ||
=== Indices of multiple elements === | === Indices of multiple elements === | ||
<source lang=apl inline>∊</source> gives us a mask for elements (characters) in the left argument that are members of the right argument: | <source lang=apl inline>∊</source> gives us a mask for elements (characters) in the left argument that are members of the right argument: |