Anonymous user
Closures/Value capture: Difference between revisions
→{{header|J}}
(added Nemerle) |
|||
Line 447:
=={{header|J}}==
===Explicit version===
The natural way of implementing this in J is to define a function which produces a gerund of a constant function.
Line 478 ⟶ 480:
7
slist@.(?9) ''
25</lang>
===Tacit (unorthodox) version===
In J only adverbs and conjunctions (functionals) can produce verbs (functions)... Unless they are forced to cloak as verbs; in this instance, the rank conjunction (“) cloaks as a dyadic verb.
<lang j> ( VL=. (<@:((<'"')(0:`)(,^:)&_))"0@:(^&2)@:i. 10 ) NB. Producing a list of boxed anonymous verbs (functions)
┌───┬───┬───┬───┬────┬────┬────┬────┬────┬────┐
│0"_│1"_│4"_│9"_│16"_│25"_│36"_│49"_│64"_│81"_│
└───┴───┴───┴───┴────┴────┴────┴────┴────┴────┘
>@:{&VL 5 NB. Evoking the 6th verb (function)
25"_
>@:{&VL 5 '' NB. Invoking the 6th verb with a dummy argument ('')
25</lang>
|