News for hackers. Stuff that matters.
Re:Stuff Goes Bad: Erlang in Anger by klibertp on Friday September 19, 2014 @03:56AM (#8339378)
Scoping rules? I what way do they differ? Honest question.
Re:Stuff Goes Bad: Erlang in Anger by nox_ on Friday September 19, 2014 @10:01AM (#8340519)
Variables in Elixir can be rebound, and there are no unsafe variables at all in Elixir.
Re:Stuff Goes Bad: Erlang in Anger by klibertp on Friday September 19, 2014 @02:43PM (#8341858)
I wouldn't call it "scoping" difference, although I can see why one would think about it as such. It would be a real scoping issue if you could assign variables in outer scopes from inside the nested scopes. Can you?
Re:Stuff Goes Bad: Erlang in Anger by nox_ on Saturday September 20, 2014 @09:12AM (#8344425)
You can. And even if you couldn't, what I mentioned is still different scoping rules, whether you put scare quotes or not.
Re:Stuff Goes Bad: Erlang in Anger by klibertp on Saturday September 20, 2014 @05:48PM (#8345678)
> 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.

Re:Stuff Goes Bad: Erlang in Anger by nox_ on Saturday September 20, 2014 @10:53PM (#8346158)
You introduced a closure there. Bindings set in if, case, receive, etc will spill in their surrounding environment. Obviously they won't spill outside closures without mutable terms, which BEAM lacks.

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

Re:Stuff Goes Bad: Erlang in Anger by klibertp on Tuesday September 23, 2014 @06:19AM (#8354715)
> The scoping rules aren't the same for the very reason you dismiss as an implementation detail.

Ok, this means that I need to learn some more about how scoping rules are defined and described, because apparently my current understanding is incompatible with the common one. That happens all the time if you're self-taught like me, so I simply accept this.

Thanks for discussion and the "scare quotes" term :)