January 12, 2009

Book Review: Programming Erlang, Software for a Concurrent World

To quote Joe Armstrong, author of the book Programming Erlang:

" The World is Parallel.

If we want to write programs that behave as other objects behave in the real world, then these programs will have a concurrent structure.

....

Erlang programs model how we think and interact "

This, in addition to all the buzz about Erlang, the CouchDB project and my interests in Concurrency and Distributed programming motivated me to pick up the lone copy of the book (available at my current den for book hunting) and add it to my growing library. I will be reading this book, over a period of time (Just as I am doing with Practical Common Lisp). Here you can find the chapter wise reviews of this book.

Let's begin.

Chapter 1: Begin

This chapter is, what you would call the pitch for the book and the introduction to the rest of the book. So, why should you bother to learn yet another programming language? You should, if (here are some of them):
  • You want to write programs which run faster when you run them on a multi-core computer
  • You want to write fault-tolerant applications that may be modified on the go without disrupting its execution (A bit of look-ahead into the chapter reveals that in Section 16.1: The Road to the Generic Server, the author talks about techniques of writing such an application)
  • You want to learn and see Functional Programming in real-world action
Here are some notes from the rest of the chapter:
  • Erlang is all about Concurrency-oriented programming. Concurrency is built into the language, rather than depending on the native operating system.
  • Erlang is all about modelling concurrency and mapping those models onto computer programs
  • In the Erlang world, there are parallel processes, which interact by pure message passing- no shared memory, and hence no shared memory corruption- no locks, no mutexes
The chapter ends with acknowledgements from the author.

Chapter 2:Getting Started
The chapter starts off with a short roadmap for learning Erlang. Next couple of pages in the chapter are dedicated to getting your Erlang development environment ready by installing the Erlang compilers and libraries.

The author, then starts of some Erlang programming with the Erlang command interpreter- Erlang shell:
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5 (abort with ^G)

After some play, two very important Erlang concepts are introduced:
  1. Erlang has variables that do not vary

  2. '=' is not an assignment operator. That is, 'X=6' does not assign 6 to X. It is in fact pattern matching. A expression like 'X=6' is actually checking if RHS=LHS. When Erlang encounters such an operation with X for the first time, it binds 6 to X. X is now bound. Now any further attempt to bind X to another value will result in an error like this (You may get a different error message; see errata: http://www.pragprog.com/titles/jaerlang/errata) :** exception error: no match of right hand side value 6

Here is a simple Erlang session to better illustrate Erlang's variable binding/pattern matching:

Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]
re>r
Eshell V5.6.5 (abort with ^G)
1> X = 10.
10
2> X = 6.
** exception error: no match of right hand side value 6
3> X = Y.
* 1: variable 'Y' is unbound
4> X = 6.
** exception error: no match of right hand side value 6
5> Y = 10.
10
6> Y = 11.
** exception error: no match of right hand side value 11
7> X = X=1.
** exception error: no match of right hand side value 1
8> X = X + 1.
** exception error: no match of right hand side value 11
9> X = Y.
10

Next, data structures/types like atoms, tuples, lists and Strings are introduced. Unification- extracting variables using pattern matching is discussed.

Strings in Erlang:

10> [97, 99, 122].
"acz"
11> [97, 99, 123].
"ac{"
12> [98, 99, 123].
"bc{"
13> [90, 99, 123].
"Zc{"
14> [1, 99, 123].
[1,99,123]

The chapter ends with a tabular recap of pattern matching and using it for unification.

Chapter 3: Coming up

2 comments:

kiss said...

WoW shares many wow gold of its features with previously launched games. Essentially, you battle with wow gold cheap monsters and traverse the countryside, by yourself or as a buy cheap wow gold team, find challenging tasks, and go on to higher aoc gold levels as you gain skill and experience. In the course of your journey, you will be gaining new powers that are increased as your skill rating goes up. All the same, in terms of its features and quality, that is a ture stroy for this.WoW is far ahead of all other games of the genre the cheap warhammer gold game undoubtedly is in a league of its own and cheapest wow gold playing it is another experience altogether.

game4power.comEven though WoW is a Cheap Wow Gold rather complicated game, the controls and interface are done in warhammer gold such a way that you don't feel the complexity. A good feature of the game is that it Cheapest Wow Gold does not put off people with lengthy manuals. The instructions cannot be simpler and the pop up tips can help you start playing the game World Of Warcraft Gold immediately. If on the other hand, you need a detailed manual, the instructions are there for you to access. Buy wow gold in this site,good for you, BUY WOW GOLD.

kiss said...

Weekends to peopleig2tmean that they can have a two-day wowgold4europe good rest. For example, people gameusdcan go out to enjoy themselves or get meinwowgoldtogether with relatives and friends to talk with each storeingameother or watch interesting video tapes with the speebiewhole family.
Everyone spends agamegoldweekends in his ownmmoflyway. Within two days,some people can relax themselves by listening to music, reading novels,or watchingogeworld films. Others perhaps are more active by playing basketball,wimming ormmorpgvipdancing. Different people have different gamesavorrelaxations.
I often spend weekends withoggsalemy family or my friends. Sometimes my parents take me on a visit to their old friends. Sometimesgamersell I go to the library to study or borrow some books tommovirtexgain much knowledge. I also go to see various exhibition to broadenrpg tradermy vision. An excursion to seashore or mountain resorts is my favorite way of spending weekends. Weekends are always enjoyable for me.

Post a Comment