First-class functions: Difference between revisions

Content added Content deleted
Line 1,400: Line 1,400:
<lang j> train =. (<'`:')(0:`)(,^:)&6 NB. Producing the function train corresponding to the functional `:6
<lang j> train =. (<'`:')(0:`)(,^:)&6 NB. Producing the function train corresponding to the functional `:6
inverse=. (<'^:')(0:`)(,^:)&_1 NB. Producing the function inverse corresponding to the functional ^:_1
inverse=. (<'^:')(0:`)(,^:)&_1 NB. Producing the function inverse corresponding to the functional ^:_1
at =. (<'@:')(0:`)(,^:) NB. Producing the function at corresponding to the functional @:
compose=. (<'@:')(0:`)(,^:) NB. Producing the function compose corresponding to the functional @:
an =. <@:((,'0') ; ]) NB. Producing the atomic representation of a noun
an =. <@:((,'0') ; ]) NB. Producing the atomic representation of a noun
of =. train@:([ ; an) NB. Evaluating a function for an argument
of =. train@:([ ; an) NB. Evaluating a function for an argument
Line 1,413: Line 1,413:
│1&o.^:_1│2&o.^:_1│^&3^:_1│
│1&o.^:_1│2&o.^:_1│^&3^:_1│
└────────┴────────┴───────┘
└────────┴────────┴───────┘
]BA=. B at &.> A NB. Producing the compositions of the functions and their inverses
]BA=. B compose &.> A NB. Producing the compositions of the functions and their inverses
┌────────────────┬────────────────┬──────────────┐
┌────────────────┬────────────────┬──────────────┐
│1&o.^:_1@:(1&o.)│2&o.^:_1@:(2&o.)│^&3^:_1@:(^&3)│
│1&o.^:_1@:(1&o.)│2&o.^:_1@:(2&o.)│^&3^:_1@:(^&3)│
└────────────────┴────────────────┴──────────────┘
└────────────────┴────────────────┴──────────────┘
BA of &> 0.5 NB. Evaluating the compositions at 0.5
BA of &> 0.5 NB. Evaluating the compositions at 0.5
0.5 0.5 0.5</lang>
0.5 0.5 0.5
</lang>


=={{header|Java}}==
=={{header|Java}}==