News for hackers. Stuff that matters.
Re:Erlang for Skeptics by KevinMS on Sunday November 29, 2009 @10:38AM (#966404)
I've done some programming in Erlang and I found the immutable variables to be a total pain in the ass that gave no benefit. Your code ends up littered with var=1 var2=var+1 type idioms.

Also, the immutable variable have nothing to do with concurrency. Since threads cant touch each others data, and they can only talk to each other through messages, immutability only applies to a local scope, where its really no big deal.

Last time I checked somebody was making a scripting language built on top of the erlang runtime and he says that immutable variables are nonsense.

Re:Erlang for Skeptics by iamaleksey on Sunday November 29, 2009 @11:11AM (#966433)
If your code ends up littered with Var2 = Var1 + 1 type "idioms", then you are probably doing it wrong. I hardly ever write code like that (or see other's Erlang code like that). It's by no means an idiom.
Re:Erlang for Skeptics by KevinMS on Sunday November 29, 2009 @02:27PM (#966666)
From programming erlang by Joe Armstrong:

At this point you might be wondering how it’s possible to program with- out variables. How can you express something like X = X + 1 in Erlang? The answer is easy. Invent a new variable whose name hasn’t been used before (say X1), and write X1 = X + 1.

  X=#todo{}.
  X1 = #todo{status=urgent, text="Fix errata in book"}.
  X2 = X1#todo{status=done}.
From Armstrongs thesis

  X = 5; X1 = X + 10;
I found those just by searching on "X1". There are more X1 examples in the erlang otp sources. Who knows what else is in there.
Re:Erlang for Skeptics by iamaleksey on Sunday November 29, 2009 @02:52PM (#966697)
I'm not saying this never happens.

It does, but you'll rarely see this pattern in any real Erlang code base. And when you see it, it will not be "littered". It's an exception, not an idiom.

And those samples from Joe's book and thesis are just snippets with no context. BTW, O'Reilly's "Erlang Programming" doesn't even provide such an example.

Edit: One example when I do use this pattern is constructing proplists for some function calls.

Re:Erlang for Skeptics by silentbicycle on Sunday November 29, 2009 @09:54PM (#967243)
Erlang's style was very strongly influenced by Prolog, and in Prolog code, it's quite common to see e.g. "X1 = X + 1", but having X2, X3, etc. as well is rare - there's usually not a succession of modified versions of a variable in the same function (clause), because it's a sign that you could break things up better. The same is true in Erlang - code with several such variables is written with a strong Java accent (or whatever), not in idiomatic Erlang.
Re:Erlang for Skeptics by artsrc on Sunday November 29, 2009 @06:33PM (#967042)
You can say the same thing another way. If your code is littered with V2 = V1 + 1 "idioms", then you are coding in a way not well supported by Erlang.

Or, rebinding variables is generally not the clearest way to express the intent of your calculation. Abstractions like fold are more pure descriptions of the desired calculation.

I do agree with the consensus that the clojure recur, expresses something about intent that is missing from Erlang.

I enjoy functional depictions of algorithms, but there are many programmers who are currently more comfortable with imperative code.

Re:Erlang for Skeptics by cloudhead on Sunday November 29, 2009 @01:13PM (#966564)
Your code will only end up with all those variables if you program in an imperative style — why are you creating unnecessary state?
Re:Erlang for Skeptics by rvirding on Sunday November 29, 2009 @04:40PM (#966849)
The only time it is sensible to do this with variable names is when they are some form of logical progression, for example when threading a state variable through the code which may be modified.

  f(..., State0) ->
    {A,State1} = foo(..., State0),
    {B,State2} = bar(..., State1),
    {C,State3} = baz(..., State2),
    Res = fubar(A, B, C, ...),
    {Res,State3}.
Otherwise you just create confusion.
Re:Erlang for Skeptics by davidw on Sunday November 29, 2009 @12:36PM (#966521)
iamaleksey is right that you should stop and think about what you're doing if you have a lot of that kind of Erlang code.

The guy you're looking for is Tony Arcieri, and his language is Reia. And here's the FAQ about assignments:

http://wiki.reia-lang.org/wiki/FAQ#Destructive_assignment.3F...