1
edit
(add diagam) |
m (Fix code) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[File:Function compositions.png|thumb|right|Diagrams of [[function | [[File:Function compositions.png|thumb|right|Diagrams of [[function composition]]s, an important part of tacit programming.]] | ||
'''Tacit programming''', also called '''[[wikipedia:Tacit_programming|point-free style]]''', refers to usage of tacit [[function]]s that are defined in terms of implicit [[argument]]s. This is in contrast to the explicit use of arguments in [[dfn]]s (<syntaxhighlight inline lang=apl>⍺ ⍵</syntaxhighlight>) and [[tradfn]]s (which have named arguments). Some APL dialects allow to combine functions into [[train]]s following a small set of rules. This allows creating complex [[derived function]]s without specifying any arguments explicitly. | '''Tacit programming''', also called '''[[wikipedia:Tacit_programming|point-free style]]''', refers to usage of tacit [[function]]s that are defined in terms of implicit [[argument]]s. This is in contrast to the explicit use of arguments in [[dfn]]s (<syntaxhighlight inline lang=apl>⍺ ⍵</syntaxhighlight>) and [[tradfn]]s (which have named arguments). Some APL dialects allow to combine functions into [[train]]s following a small set of rules. This allows creating complex [[derived function]]s without specifying any arguments explicitly. | ||
Line 21: | Line 21: | ||
Dot ← +.× | Dot ← +.× | ||
3 1 4 | 3 1 4 Dot 2 7 1 | ||
17 | 17 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Derived operators == | == Derived operators == | ||
A dyadic operator with its right operand forms a tacit monadic operator: | A dyadic operator with its right operand forms a tacit monadic operator: | ||
Line 37: | Line 38: | ||
A [[train]] is a series of functions in isolation. An isolated function is either surrounded by parentheses or named. | A [[train]] is a series of functions in isolation. An isolated function is either surrounded by parentheses or named. | ||
These rules are used for 3-trains: | These rules are used for 3-trains, called [[fork]]s: | ||
{| | {| | ||
|<syntaxhighlight lang=apl> (f g h) ⍵</syntaxhighlight>|| {{←→}} ||<syntaxhighlight lang=apl>( f ⍵) g ( h ⍵)</syntaxhighlight> | |<syntaxhighlight lang=apl> (f g h) ⍵</syntaxhighlight>|| {{←→}} ||<syntaxhighlight lang=apl>( f ⍵) g ( h ⍵)</syntaxhighlight> | ||
Line 50: | Line 51: | ||
|} | |} | ||
In APL (but not [[J]]), these rules are used for 2-trains: | In APL (but not [[J]]), these rules are used for 2-trains, called [[atop]]s: | ||
{| | {| | ||
|<syntaxhighlight lang=apl> (g h) ⍵</syntaxhighlight>|| {{←→}} ||<syntaxhighlight lang=apl>g ( h ⍵)</syntaxhighlight> | |<syntaxhighlight lang=apl> (g h) ⍵</syntaxhighlight>|| {{←→}} ||<syntaxhighlight lang=apl>g ( h ⍵)</syntaxhighlight> | ||
Line 66: | Line 67: | ||
|<syntaxhighlight lang=apl>(⊢ g f) ⍵</syntaxhighlight>|| {{←→}} ||<syntaxhighlight lang=apl>g∘f⍨ ⍵</syntaxhighlight> | |<syntaxhighlight lang=apl>(⊢ g f) ⍵</syntaxhighlight>|| {{←→}} ||<syntaxhighlight lang=apl>g∘f⍨ ⍵</syntaxhighlight> | ||
|} | |} | ||
== Debugging == | == Debugging == | ||
Line 197: | Line 197: | ||
666 ⍝ the sum of the squares of the primes up to 17 | 666 ⍝ the sum of the squares of the primes up to 17 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Note that <syntaxhighlight lang=apl inline>(( | Note that <syntaxhighlight lang=apl inline>((⊢~∘.×⍨)1↓⍳)</syntaxhighlight> is a train computing primes up to the given input. | ||
A more satisfying variation of the accursed train is the following. | A more satisfying variation of the accursed train is the following. |
edit