Re: message-driven function: more explanation

*To*: mathgroup at smc.vnet.net*Subject*: [mg95660] Re: message-driven function: more explanation*From*: Mariano Suárez-Alvarez <mariano.suarezalvarez at gmail.com>*Date*: Sat, 24 Jan 2009 06:18:38 -0500 (EST)*References*: <gl9n6q$aus$1@smc.vnet.net> <glc50f$3b3$1@smc.vnet.net>

On Jan 23, 8:09 am, dh <d... at metrohm.com> wrote: > Hi Bert, > > nothing exotic here. The return value is a function that consits of a > > [snip] Well, there is one thing which may be mildly exotic for those not familiar with it: the function is returned is wrapped by a closure, which is why it is able to retain the value of the counter variable. (The closure is not air-tight, though: In[1]:= f[a_] := Module[{aa = a, ff}, ff[i_] := (aa += i; aa); ff ]; In[2]:= q = f[0] Out[2]= ff$14 In[3]:= q[2] Out[3]= 2 In[4]:= aa$14 = 0; In[5]:= q[3] Out[5]= 3 Can one get a really closed closure?) -- m