Trains: Difference between revisions
(New page: <table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""> <tr> <td> <table border="0" cellpadding="5" cellspacing="0" summary=""> <tr> <td><apll>Z←(f g) ...) |
No edit summary |
||
Line 37: | Line 37: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td><apll>L</apll> and <apll>R</apll> are arbitrary arrays. | <td><apll>L</apll> and <apll>R</apll> are arbitrary arrays, <apll>f</apll>, <apll>g</apll>, <apll>h</apll>, etc, are arbitrary functions of any type: primitive, user-defined, system, and/or derived.</td> | ||
</tr> | </tr> | ||
</table> | </table> |
Revision as of 21:38, 17 February 2009
|
||||||||||||||||||||
L and R are arbitrary arrays, f, g, h, etc, are arbitrary functions of any type: primitive, user-defined, system, and/or derived. |
This clever idea from the designers of J is called Trains where a parenthesized sequence of functions (which normally would signal a SYNTAX ERROR) can be interpreted as per the above descriptions. Note that the spacing between functions is for visual purposes only — it has no effect on the interpretation.
For example,
(,⍎)'2+3'
←→ '2+3',⍎'2+3'
←→ '2+3',5
2+3 5
avg←(+/ ÷ ⍴) defines a function that computes the average of a numeric vector.
avg 1 2 3 4
←→ (+/ ÷ ⍴) 1 2 3 4
←→ (+/1 2 3 4) ÷ ⍴1 2 3 4
←→ 10 ÷ ,4
2.5
Longer Trains are defined as follows:
(e f g h) ←→ (e (f g h))
(d e f g h) ←→ (d e (f g h))
and in general
Even length: (a b c ...) ←→ (a (b c ...))
Odd length: (a b c ...) ←→ (a b (c ...))
For more applications of this concept, see the discussion in the Learning J manual.