4,494
edits
(→Debugging: new section) |
(→Trains) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 36: | Line 36: | ||
A train is a series of functions in isolation. An isolated function is either surrounded by parentheses or named. Below, <source lang=apl inline>⍺</source> and <source lang=apl inline>⍵</source> refer to the arguments of the train. <source lang=apl inline>f</source>, <source lang=apl inline>g</source>, and <source lang=apl inline>h</source> are functions (which themselves can be tacit or not), and <source lang=apl inline>A</source> is an array. The arguments are processed by the following rules: | A train is a series of functions in isolation. An isolated function is either surrounded by parentheses or named. Below, <source lang=apl inline>⍺</source> and <source lang=apl inline>⍵</source> refer to the arguments of the train. <source lang=apl inline>f</source>, <source lang=apl inline>g</source>, and <source lang=apl inline>h</source> are functions (which themselves can be tacit or not), and <source lang=apl inline>A</source> is an array. The arguments are processed by the following rules: | ||
=== Forks === | |||
A 3-train is a ''fork'': | A 3-train is a ''fork'': | ||
{| | {| | ||
Line 53: | Line 48: | ||
|- | |- | ||
|<source lang=apl>⍺ (A g h) ⍵</source>|| {{←→}} ||<source lang=apl>A g (⍺ h ⍵)</source> | |<source lang=apl>⍺ (A g h) ⍵</source>|| {{←→}} ||<source lang=apl>A g (⍺ h ⍵)</source> | ||
|} | |||
=== Atops === | |||
A 2-train is an ''atop'': | |||
{| | |||
|<source lang=apl> (g h) ⍵</source>|| {{←→}} ||<source lang=apl>g ( h ⍵)</source> | |||
|- | |||
|<source lang=apl>⍺ (g h) ⍵</source>|| {{←→}} ||<source lang=apl>g (⍺ h ⍵)</source> | |||
|} | |} | ||
Line 60: | Line 63: | ||
In [[Dyalog APL]], analysis of trains is assisted by a [[user command]] <source lang=apl inline>]Boxing on</source>. This is achieved by executing the command <source lang=apl inline>]Boxing on</source> and then entering a train without any parameters. A structure of the train will be displayed. | In [[Dyalog APL]], analysis of trains is assisted by a [[user command]] <source lang=apl inline>]Boxing on</source>. This is achieved by executing the command <source lang=apl inline>]Boxing on</source> and then entering a train without any parameters. A structure of the train will be displayed. | ||
For example, the "accursed train" from the section below can be | For example, the "accursed train" from the section below can be analysed like this: | ||
<source lang=apl> | <source lang=apl> | ||
]Boxing on | ]Boxing on | ||
Was OFF | |||
((+.×⍨⊢~∘.×⍨)1↓⍳) ⍝ the train to be analysed | ((+.×⍨⊢~∘.×⍨)1↓⍳) ⍝ the train to be analysed | ||
┌───────────────────────────────┬───────┐ | ┌───────────────────────────────┬───────┐ | ||
│┌───────────┬─────────────────┐│┌─┬─┬─┐│ | │┌───────────┬─────────────────┐│┌─┬─┬─┐│ | ||
││┌───────┬─┐│┌─┬─┬───────────┐│││1│↓│⍳││ | |||
│││┌─┬─┬─┐│⍨│││⊢│~ | │││┌─┬─┬─┐│⍨│││⊢│~│┌───────┬─┐│││└─┴─┴─┘│ | ||
││││+│.│×││ │││ │ | ││││+│.│×││ │││ │ ││┌─┬─┬─┐│⍨││││ │ | ||
│││└─┴─┴─┘│ │││ │ │││∘│.│×││ | │││└─┴─┴─┘│ │││ │ │││∘│.│×││ ││││ │ | ||
││└───────┴─┘││ │ ││└─┴─┴─┘│ ││││ │ | ││└───────┴─┘││ │ ││└─┴─┴─┘│ ││││ │ | ||
││ ││ │ │└───────┴─┘│││ │ | ││ ││ │ │└───────┴─┘│││ │ | ||
Line 83: | Line 84: | ||
<source lang=apl> | <source lang=apl> | ||
]Boxing on -trains=tree | ]Boxing on -trains=tree | ||
Was ON -trains=box | |||
((+.×⍨⊢~∘.×⍨)1↓⍳) ⍝ the train to be analysed | ((+.×⍨⊢~∘.×⍨)1↓⍳) ⍝ the train to be analysed | ||
┌───┴───┐ | ┌───┴───┐ | ||
Line 95: | Line 94: | ||
+ × ┌┴┐ | + × ┌┴┐ | ||
∘ × | ∘ × | ||
</source> | |||
Or fully parenthesised: | |||
<source lang=apl> | |||
]Boxing on -trains=parens | |||
Was OFF -trains=box | |||
((+.×⍨⊢~∘.×⍨)1↓⍳) ⍝ the train to be analysed | |||
(((+.×)⍨)(⊢~((∘.×)⍨)))(1↓⍳) | |||
</source> | </source> | ||