First-class functions/Use numbers analogously: Difference between revisions

(Added Kotlin)
Line 652:
 
=={{header|J}}==
 
===Explicit version===
 
This seems to satisfy the new problem statement:
 
Line 672 ⟶ 675:
 
For contrast, here are the final results from [[First-class functions#J]]:
 
<lang> BA unqcol 0.5
0.5 0.5 0.5 0.5</lang>
 
===Tacit (unorthodox) version===
Although the pseudo-code to generate the numbers can certainly be written (see above *** ) it is not done for this version because it would destroy part of the analogy (J encourages, from the programming perspective, to process all the components at once as opposed to one component at a time).
 
<lang> multiplier=. train@:((;:'&*') ;~ an@: *)
]A=. 2 ; 4 ; (2 + 4) NB. Corresponds to ]A=. box (1&o.)`(2&o.)`(^&3)
┌─┬─┬─┐
│2│4│6│
└─┴─┴─┘
]B=. %&.> A NB. Corresponds to ]B =. inverse&.> A
┌───┬────┬────────┐
│0.5│0.25│0.166667│
└───┴────┴────────┘
]BA=. B multiplier&.> A NB. Corresponds to B compose&.> A
┌───┬───┬───┐
│1&*│1&*│1&*│
└───┴───┴───┘
BA of &> 0.5 NB. Corresponds to BA of &> 0.5 (exactly)
0.5 0.5 0.5</lang>
 
Please refer to [http://rosettacode.org/wiki/First-class_functions#Tacit_.28unorthodox.29_version First-class functions tacit (unorthodox version)] for the definitions of the functions train, an and of.
 
=={{header|jq}}==
Anonymous user