|
|
|
|
|
by klibertp
4285 days ago
|
|
> what I mentioned is still different scoping rules You're probably right, I don't want to argue about terminology. What do you mean by "scare quotes"? Honest question: English is my second language and I'm not very good with it. > You can. You're wrong. Here, take a look: iex(4)> f = fn() -> a = 0; (fn()->a=9 end).(); a end
#Function<20.80484245/0 in :erl_eval.expr/5>
iex(5)> f.()
0
f.() should evaluate to 9 if what you said was true. Either there's a special syntax for doing this in Elixir (like nonlocal in Python 3) or it's absent, and then the scoping rules are the same in Elixir and Erlang, with a bit of syntactic sugar for SSA transformation, which you need to do by hand in Erlang.Again, I'm not Elixir programmer, so this is a honest question: is there some special syntax which would make the example above produce 9? I doubt it very much because it wouldn't fit very well with BEAM, but everything is possible and I'd be glad to learn about another nice feature of Elixir. |
|
The bits about SSA transformation needed to be done by hand in Erlang are a bit fun, because that's considered a feature in the Erlang realm.
The scoping rules aren't the same for the very reason you dismiss as an implementation detail.
Scare quotes: http://en.wikipedia.org/wiki/Scare_quotes