Sure, you can make a simple change to pull the value out of the closure
environment:
type tmptype
func1::Function
func2::Function
end
function testit2()
global e=2
_func1 = function()
e = e+2
e
end
_func2 = function()
e = e+2
e
end
tmptype(_func1,_func2)
end
f.env and Box are implementation details of the current (aka subject to
change), and aren't intended for inspection or manipulation by code
On Fri Jan 23 2015 at 9:20:19 AM Wolfram <[email protected]> wrote:
> Hi! I get this example to show what I want to do.
>
> function testit()
> e=2
> function()
> e = e+2
> e
> end
> end
>
> testit() return anonymous function
> func = testit()
>
> Each time, we run func(), e+2.
> func()
> 4
> func()
> 6
> func()
> 8
> It shows that func() can keep a value of e, after testit() is evaluated.
>
> run:
>
> func.env
> (Box(8),)
>
> There seems to be an enviroment for this anonymous function.
>
> We can also try
> type tmptype
> func1::Function
> func2::Function
> end
>
> function testit2()
> e=2
> _func1 = function()
> e = e+2
> e
> end
> _func2 = function()
> e = e+2
> e
> end
> tmptype(_func1,_func2)
> end
>
> run:
> double_func = testit2()
>
> The value of double_func.func1.env and double_func.func2.env will be
> synchronized.
>
> run:
> double_func.func1()
> It will change the value of double_func.func2.env too.
>
> Finally, here is my question.
>
> It is there any way to change the value of the special `e` without
> evaluating double_func.func1() or double_func.func2(), and keep double_func
> .func1.env and double_func.func2.env synchronized.
>
> Is there any way to get a reference of the special `e`, bind it to a name
> in Main, and change the value in the Box(). It let us change `e` in func2.env
> and func1.env, without running double_func.func2()
>
> Why this value get a Box().
>
> Thanks!
>
>
>
>
>
>