Here's a quick test:

function make_counter(x)
  return (delta) -> begin
    x += delta
    x
  end
end

c0 = make_counter(0)
c1 = make_counter(0)

c0(1) # 1
c1(1) # 1
c0(1) # 2
c1(1) # 2

So it looks like they don't share the bound 'x' variable.


On Friday, August 15, 2014 11:50:03 AM UTC-4, Noah Brenowitz wrote:
>
> suppose I have a function with prototype  "f(x, y, z)". How can bind one 
> of the arguments to a new function argument by copying vs reference? In 
> c++11 I could do 
>
> z = ... ;
> auto newfun = [=](x,y) { f(x,y, z)}; 
>
> if I wanted newfun to have its own copy of z. Then I could make some 
> changes to original object z without affecting the evaluation of newfun. An 
> alternative way to do this would be using a "Functor class" or std::bind. 
> Is it possible to replicate this behavior in julia? 
>

Reply via email to