No F*cking Idea

Common answer to everything

Erlang E17 and Second Edition of Programming Erlang

| Comments

Today I got my hands on Programming Erlang 2ed. And i have to make a spoiler now. The book is great. I remember the times when i was reading “Programing Erlang” and it was a great book. I enjoyed it and it made me get into erlang I was a really happy person.

This book is talking about R17. From what i read R17 should be named Erlang 2.0 the changes are just amazing.

My face after reading changes…

Vomiting Rainbow

Page 75 Maps

This chapter hits you in the face! I don’t have yet E17 to check more stuff but this looks amazing. Ok lets have a look. In Erlang E17 they are introducing MAPS. Also known as key-val’s / hashes / assoccs / dictionary. Basically a data structure that lets you store a value with a key and retrieve the value if you know the right key.

Lets have a look at the syntax.

maps
1
λ  Kv = #{a => 1, b => 2, c => 3}.

This creates a map with 3 elements a,b and c. Easy. Of course maps are immutable data structures so if you want to add stuff you need to do it like this

maps2
1
λ  Kv2 = Kv#{d => 4}.

So it is similar to updating records but imho the true power is in retrieving data and pattern matching on maps. YES PATTERN MATCHING.

maps3
1
2
3
λ  #{b => B, c => C} = Kv2.
λ  B.
λ> 2

Isn’t this amazing!? You can use maps like in ruby and pattern match on them. And i was just about to scream from joy when…

i saw this.

Maps –> Json

Yes you can serialize and deserialize maps to json. WTF ?! Yes.

maps4
1
λ maps:to_json(Map) -> Bin

Calling maps:to_json you can make from map a json and by calling

maps5
1
2
λ maps:from_json(Bin) -> Map
λ maps:save_from_json(Bin) -> Map

Gives you option to load maps from binaries! C’mon! this is amazing. Safe version will explode if you try to flood VM with not existing atoms. This is useful! because atoms are never GC’ed!

Yes new MAPs are amazing! I love them :> This sloves so many problems and resolved so many situations when you had to write boilerplate code. Amazing work!

Page 287 Programing with Websockets and Erlang

Is also new thing i love this chapter as it shows you how to tackle real thing which is websockets :) it is very cool addition to the book and also a free sample so you can read it on your own before buying book.

http://media.pragprog.com/titles/jaerlang2/websockets.pdf

Addition of Dializer and Rebar

This is great from empiric point of view as Joe shows how to use rebar and build real life code using github. This is a great thing and worth reading. I love it :) You get real life example… i get here everything i lacked in previous book.

Summary

Every single new thing in the book is great. Stuff about E17 version of Erlang is just great. I don’t have E17 yet on my box but this will be by far best release of Erlang. In chapter about maps he talks about looking at ruby. I think it is a bit inspired by ruby builtin syntax for hashes by yet again. This is amazing and in future this will resolve so many problems and make many API’s much more useful. You don’t have to type anymore ton of _ if you want to pattern match on big tuple. You can match on a key.

I spend an hour reading the book on the train from London to Epsom and all I can say. It is great!. I love it and i love new changes!

Comments