MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: message-driven function: more explanation



Hello,

to my knowledge, there is no 100% closed closure in Mathematica. Instead, we may 

"bury" names arbitrarily deep into contexts. E.g. we may bury the 

counter in MyContext`:

f1[] := Module[{MyContext`co},

   MyContext`co = 0;

   Function[{}, ++MyContext`co]

   ]



Daniel



Mariano Suárez-Alvarez wrote:

> 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

> 




  • Prev by Date: Re: two plots in Mathemtica 7. Bug?
  • Next by Date: Re: two plots in Mathemtica 7. Bug?
  • Previous by thread: Re: message-driven function: more explanation
  • Next by thread: Re: Basic questions on list manipulation in the "Mathematica Way"