Hacker News new | past | comments | ask | show | jobs | submit login

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?



You can. And even if you couldn't, what I mentioned is still different scoping rules, whether you put scare quotes or not.


> 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.


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


> 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 :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: