$ irb
irb(main):001:0> a = 1
=> 1
irb(main):002:0> f = proc do
irb(main):003:1* a = 2
irb(main):004:1> end
=> #<Proc:0x007fa7fd02f740@(irb):2>
irb(main):005:0> f.call
=> 2
irb(main):006:0> a
=> 2
But in Elixir, variable not changed:
$ iex
Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (0.10.4-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> a = 1
1
iex(2)> f = fn () -> a = 2 end
#Function<20.80484245 in :erl_eval.expr/5>
iex(3)> f.()
2
iex(4)> a
1
How to change it? I want to change the variable in callback function.
Best regards.
x = 1execute_in_thread { x = 2 }
# Do something more
puts x
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.