Friday, August 1, 2008

Erlang, Multiple Assignment, and Closures

There's been some discussion on the tubes recently about the value of Erlang's single-assignment semantics, with people weighing in on both sides.

However, no one seems to be asking the key question, namely what happens when you mix closures (which already exist in Erlang) with multiple-assignment variables? That's probably because the answer is a bit messy: you get an object-oriented language.

To see why this is the case, let's go ahead and define a Person class in this (hypothetical) Erlang variant. The Person class has a single Name field and corresponding getter and setter methods:


new_person(Name) ->
get_name=fun() ->
set_name=fun(NewName) ->
Name = NewName % Multiple assignment
That's all there is to it. The arguments to the function (i.e. Name) act as the fields of the object, and the anonymous functions assigned to the record (i.e. get_name and set_name) act as the methods. This means we can now create Person objects, pass them around, and modify them whenever we want:
Person = new_person("Sean Combs"),
Person#person.set_name("Puff Daddy"),

Why does this matter? Because objects have identity, and identity's a real bitch when it comes to distributed systems. In particular, a lot of questions pop up when you try to send an object over the wire to another process. Do you:

  • Copy the object, in which case any changes made to it on the remote process won't be visible locally

  • Send a reference to the object, such that any time the object is referred to in the remote process, a call is made back to the original process (at great cost to performance)

  • Let the developer indicate on an object-by-object basis which of the previous two options they would prefer

  • Punt, and simply forbid access to mutable variables from within closures.
    This is pretty limiting, to the point where it makes it impossible to even write a simple foreach function. For example, the following code, which adds the numbers [1,2,3] together, wouldn't be allowed (since Sum is mutable and accessed from a closure):
    Sum = 0, 
    foreach(fun(N)-> Sum += N end, [1,2,3]),

    Assuming we're OK with this, we still have to deal with the fact that we now have two types of variables in the language: mutable and immutable. Therefore we must either:

    • Prefix immutable variables with "final" to indicate they can be used within a closure

    • Prefix mutable variables with "var" to indicate they cannot be used within a closure

    • Rely on the compiler to infer which variables are mutable and which are used within closures (possibly producing some very cryptic error messages)

    • Take a "snapshot" of all variables in scope when a closure is created, and ignore any subsequent changes to the variable. For example, the following code would print "foo":

      Name = "foo",
      PrintName = fun() -> print(Name) end,
      Name = "bar",

      But this would print "bar":

      Name = "foo",
      Name = "bar",
      PrintName = fun() -> print(Name) end,

      Confusing, to say the least.

Personally, I don't find any of these options very appealing. But if you really want multiple-assignment variables in Erlang, you're going to have to pick one of them.


Clover said...

Spotted your write – ups, it’s cool. Very beneficial and interesting there are some ideas I haven’t heard before. Thanks for sharing.


sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.

lee woo said...

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.

Anuska JAIN said...

It is a pressurized situation of managing the recipes items and it has to be cleaned and cleaned efficiently. We should also use the unique material and sponge to make it dry. Packers and Movers Pune
Packers and Movers Bangalore
Packers and Movers Delhi
Packers and Movers Gurgaon

Anuska JAIN said...

If we use the soap 100 % 100 % absolutely 100 % totally 100 % totally free plate fresh bar items, it can be cleaned definitely. Packers and Movers Chennai
Packers and Movers Hyderabad
Packers and Movers Mumbai
Packers and Movers Noida

andrea chiu said...

Thanks for sharing your article and for giving us the chance to read it. It is very helpful and encouraging. Visit my site too.

John Cena said...

Thanks for nice information

Packers and Movers Bangalore
Packers and Movers Pune

John Cena said...

Thanks to post this helpful article

Packers and Movers Bangalore
Packers and Movers Pune

Hot Gurgaon Call Girls said...

Escort in connaught place
Escort in dlf phase
Escort in golfcourse
Escort in sushantlok
Escort in sarjapur
Escort in manesar
Escort in neemrana
call Girls in behror

Sandhya Mane said...

Mumbai Escorts
Mumbai Escorts Service
Juhu Escorts Service
Call Girl Mumbai 
Bandra Escorts Service
Escort Girls in Mumbai

Delhi Escorts Service
Pune Escorts Service
Bangalore Escorts Service
Goa Escorts Service
Chennai Escorts Service
Kolkata Escorts Service
Ahmedabad & Surat Escorts Service
Darjeeling Escorts Service
Mumbai Escorts Service

Cindy Dy said...

I am very happy to locate your website. I just wanted to thank you for the time you spent on this great article. I definitely enjoyed reading it and I have you bookmarked to check out new stuff you post.


Anonymous said...

Thanks for your post. Click to play !

- Mortal Kombat XL
- Atari Breakout
- Dragon Ball Z Games

packers and movers hyderabad said...

There's a lot of interesting info here! I'm very grateful for the post! movers and packers hyderabad , is here to make your life simpler.
Packers And Movers Hyderabad Packers And Movers is recognized as a business manager providing wide-ranging and differentiate service appearance as well as Relocation Shifting, Logistics and Transportation, Facilities managing, strategy & Designing services.

Packers And Movers Jaipur said...

An excellent information provided thanks for all the information i must say great efforts made by you.
thanks a lot for all the information you provided.
please visit our official website for further details-
Packers And Movers Jaipur

jon rai said...

For More details:-
Movers and Packers in Hyderabad
Movers and Packers Pune
Movers and packers gurgaon
movers and packers Bangalore
movers and packers Mumbai
Movers and Packers delhi

jon rai said...

[url=] packers and movers in hyderabad [/url] @ [url=][/url]
[url=]Packers and Movers in Pune [/url]@ [url=][/url]
[url=] Packers and Movers Bangalore [/url]@ [url=][/url]
[url=]Packers and Movers Gurgaon[/url] @ [url=][/url]

jon rai said...

For Free Query Visit:-

Packers and movers in Bangalore @
Packers and Movers Hyderabad @
Packers and Movers Pune @
Packers and Movers Mumbai @
Packers and Movers Gurgaon @
Packers and Movers Pune @

Jagat Tiwari said...

Packers and Movers in Hyderabad
Packers and Movers in Bangalore

Jagat Tiwari said...

Packers and Movers in Delhi
Packers and Movers in Gurgaon

Jagat Tiwari said...

Packers and Movers in Hyderabad
Packers and Movers in Bangalore

Jagat Tiwari said...

Packers and Movers in Mumbai
Packers and Movers in Pune

Ankansha said...

There's nothing called failure as we call it. I call it minimal effort that can be turned around.

Chaitali Roy said...

Packers and Movers Bangalore
Packers and movers Pune
Packers and Movers Pune
Packers and Movers Bangalore

Relocate Services said...

Packers and Movers in Bangalore
Packers and Movers in Delhi
Packers and Movers in Jaipur
Packers and Movers in Pune

Aahna Desai said...

Bangalore Escorts Services
Call Girls in Bangalore
Escorts in Bangalore
Call Girls in Bangalore

packers movers bangalore said...

Generally I don't read anything but thanks for writing when i read this i felt how graceful as a writer you are.thank you for posting-
Packers And Movers Bangalore

Mahi Sehgal said...

Escorts Service in Hyderabad
Hyderabad Escorts Service
Hyderabad Escorts
Escorts in Hyderabad

payal sharma said...

An excellent information provided thanks for all the information i must say great efforts made by you. thanks a lot for all the information you provided.
Packers And Movers Pune charges

Noor jaipur said...

Are you living in Jaipur or Jodhpur you will be staying here in a hotel, then our Escort Jaipur Noor Lady already with you within the hour. Starting at 5K you can hire a lady.

Packers Movers Gurgaon said...

Hi – It’s good to read such interesting content. I agree with much of what is written here and I’ll be coming back.
Thanks again for posting such great reading material!! To get more relevant information visit here
Packers And Movers Gurgaon
Packers And Movers In Gurgaon charges

Packers Movers Gurgaon said...

We Provide Best Packers And Movers Gurgaon List for Get Free Best Quotes, Compare Charges,
Save Money And Time, Household Shifting Services @
Packers And Movers Gurgaon charges

Relocate Services said...

This blog is very helpful to choose a moving company...
We are means a unit of Best Packers and Movers in Bangalore or any other city of India. If you want a tension free shifting at affordable charges then you are a right place we will help you to reach the best moving company. We will provide free quotations and free survey for your shifting so that you can compare the charges and services and you can choose any one which is suitable for you.
for more info visit-
Movers and Packers Bangalore
Movers and Packers Delhi
Movers and Packers Jaipur
Movers and Packers Pune

raksha jain said...

very good post which I really enjoy reading. It is not every day that I have the possibility to see something like this.
Packers and Movers Mumbai
Packers and Movers Mumbai

Meera Singh said...

Indian Independent ludhiana escort whatsapp real pictures, photos in ludhiana,

cara menggugurkan kandungan said...

This blog is so nice to me. I will continue to come here again and again. Visit my link as well. Good luck obat aborsi cara menggugurkan kandungan obat aborsi cara menggugurkan kandungan obat telat datang bulan jual obat aborsi obat penggugur kandungan tanda tanda kehamilan cara menggugurkan kandungan

Meera Singh said...

If you are looking for the best nashik escort Service.

Neha Tripathi said...

24/7 Noida Escorts Services open 24hrs.Contact us to hire Noida Escorts Provider.Find 100% Independent Escorts profiles and reviews.

Nancy Singh said...

CaLL - 09118181868
Lucknow Escort, Call Girls, Lucknow Escort ServiceS,
It has been for a while, that's entertaining as well as interesting things to consider are different kinds of
And it is the way through which some of the wonderful things can be found together.
As the main source of entertainment as well as Suzie Lucknow Escort
Pleasant service content only found in the city is said to be
Meaning there is increased importance of far broader escorting services.
It's best to enjoy meaningful content which means that some of the different source
As well as entertainment which is why do some wonderful things that have been found to be in existence yet.
CaLL - 09118181868
Lucknow call Monika 9118181868 Monika Call:- 7O7I3489O3

Hot Girl Show Down said...

AAj RAAT KA KYA HAI SCENE Call:-{7071348903 }WHATSAPP 9118181868 } Girls In Lucknow Vip Female Escort Servise.

Call 707//134//8903} Take Robin Like You Yours Choice Girls 9118181868 Hi Profiles Indian North Indian Lucknow Escort Chines Girls We Have Arrange You. So Booking Hot Girls Short And Night Sex Service In Lucknow In And InCall Service Short 6000 Night 20000 Booking Any Time 24x7 High Profiles Girls.....HIGH CLASS CHINESE/NORTH/SOUTH INDIANS MODELS/COLLEGE GIRLS/
WE ACCEPT ALL CASE PAYMENT ALSO .India Escort Service | Call Girls In India .

There is a number of and it is a difficult decision to choose the right one. Our escort company is a well-established firm that deals with customers who look for high quality service at affordable cost.
Give us a call and talk to our professional reception staff about your requirements.We are sure that we are able to find the right lady for you.


India Escort Service | Call Girls In India
India Escort Service | Call Girls In India
Escorts In India | Call Girls In India

SHORT TIME:.........6K.......8K
NIGHT TIME :........15K......20K.........24 HOURS

sikat said...

Use this article to increase your knowledge . cara menggugurkan kandungan

narendra durbakula said...

packers and movers in hyderabad

packers and movers hyderabad

packers and movers kondapur

Have you planned to move to Hyderabad? But, how confused will you manage and organize everything in order to move your goods to a new destination safely? There is a simple solution available to this confusion and it is Packers and Movers Hyderabad.

siva linga prasad said...

now days, finding the packers and movers agra is a much difficult thing. so we are providing solution for your relocation in agra.
packers and movers in agra

packers and movers agra

movers and packers in agra

movers and packers agra

packers and movers in


movers and packers pune