Alan K. Stebbens wrote:
>A programming comparison on the web had this question:
>> The problem: Write a function foo that takes a number n and returns  
>> a function that takes a number i, and returns n incremented by i.

Problem?!?  A something that takes a number n and returns a function is
an adverb (or rather: "adnoun") in J.  This one is very easy:

Welcome to J! (ctrl+d to quit) 4.05+GDS changes/Feb 16 2008/19:19:49

   inc_by =. &+                 NB. adnoun;  1 : 'm&+'   if you
                                NB. are versionally challenged.
   plusnine =. 9 inc_by         Nb. applied to noun creates a verb
   plusnine 6                   NB. does it work?
15                              NB. sure.

> The concept of embedding context within a function definition is  
> called a "closure".  Is there a "standard" way to accomplish
> closures in J?

I don't see any need to force Lisp/Scheme jargon onto J but if
you insist, I'd say that adnouns fit the bill.

   plusnine
9&+

                                                        Martin
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to