Closures/Value capture: Difference between revisions

Content added Content deleted
(added Nemerle)
Line 447: Line 447:


=={{header|J}}==
=={{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.
The natural way of implementing this in J is to define a function which produces a gerund of a constant function.
Line 478: Line 480:
7
7
slist@.(?9) ''
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>
25</lang>