Errrr…

I am doing a little “pleasure reading” on Erlang tonight. I thought this was an interesting thing to say about variables:

Variables can only be bound once! The value of a variable can never be changed once it has been set (bound).

Doesn’t that make them constants, and not variables?

cw

6 Responses to “Errrr…”

  1. michael schurter Says:

    I was going to say that perhaps set/bound means something other than assignment in erlang, but a little further down on that page says:

    A = 10
    Succeeds - binds A to 10

    Sounds like set/binds == assignment… which means variables can’t change? Well it is designed by a telecom company. ;)

  2. christian Says:

    Well, I think I am going to try and learn Erlang so maybe I’ll find out more about this. I’ll post back with any news.

    Sidebar: what’s up with your blog lately? I think last time I was there I saw some tumbleweed rolling along.

  3. Joseph Says:

    i am on Christian’s team.

    Sidebar: is it typical to post “sidebar” instead of “on another note” or “by the way” in blogs? I have never seen it before, is this common.

  4. christian Says:

    Ok, it looks like in practice that it doesn’t matter so much that you can’t reassign values to variables. This is because the reassignment is only restricted within scope. The functional nature of Erlang means that you will have a new scope often when you recurse.

    Anyhow, this tutorial is a good one:
    http://www.erlang.org/download/getting_started-5.4.pdf

    It starts to get interesting once you get into the message passing stuff.

  5. christian Says:

    Joseph: I’m not sure. I don’t know that I have ever posted a “sidebar” in a comment before. There’s a first time for everything, I suppose.

  6. gooli Says:

    We’ve all been so tainted by procedural and object oriented programming that we find it very hard to think in different terms. While algorithmic (procedural and object oriented) languages work in terms of changing the state of places in memory we refer to as variables, functional languages work differently. Completely differently. In a pure functional language there is no notion of a variable (although the term is sometimes still used), there is only a notion of a bound name - a name that represents a value.

    That sounds weird as hell at first but it can be extremely useful in certain situations like concurrent programming in which Erlang excels. Think about it. If you don’t have variables, at least not ones that can change their values, you don’t need locks. At all! There is nothing TO lock. It’s not only that two threads can’t mutate the same variable at the same time, even one thread can’t do that. That of course creates other interesting problems, like the fact that in order to change an element of an array you need to copy the entire array, changing its contents on the fly. Clearly not the most efficient way to deal with data, but there are ways around it. Also, if we are talking about massively parallel computing such as the recent take over by multi core systems seems to suggest, we may find that the rules have changed a bit. It might be more prudent to write code that runs slower on a single machine but that is safe to run on many machines in parallel.

    Enjoy Erlang and let us know how it goes. I’ve only read a bit about the language and plan to get to know it a little bit more intimately sometime soon.

Leave a Reply