On Sun, 26 Apr 2009, 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.
> 
> The concept of embedding context within a function definition is  
> called a "closure".  So, I guess I'm asking is if there is a  
> "standard" way to accomplish closures in J?
>   bar
> ┌─┬─┬───┐
> │3│:│7+y│
> └─┴─┴───┘
>   bar 3
> 10

I think that your `bar' does not satisfy the requirement. When it is
called again, it should add 10 (not 7) to the number.  This closure
had been discussed on this list and appeared in jwiki, iirc.

J is not good in this problem or this is not a good problem for J. :-)

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩150 劉禹錫  蜀先主廟
    天地英雄氣  千秋尚凜然  勢分三足鼎  業復五銖錢
    得相能開國  生兒不象賢  淒涼蜀故妓  來舞魏宮前
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to