Monday, December 17, 2007

The strange world of erlang

Sometimes I feel compelled to learn something new from the wonderful world of non-human languages (no worries, Chinese is going to keep me occupied for some foreseeable future). Since multicore processing is all the rage these days, I figured I'd read up on the oft-hyped Erlang.

This is from the book I'm reading:
We’ll start with an example. Suppose we have a list L:
1> L = [1,2,3,4,5].
And suppose we want to double every element in the list. We’ve done this before, but I’ll remind you:
2> lists:map(fun(X) -> 2*X end, L).
But there’s a much easier way that uses a list comprehension:
4> [2*X || X <- L ].
The notation [ F(X) || X <- L] means “the list of F(X) where X is taken from the list L.” Thus, [2*X || X <- L ] means “the list of 2*X where X is taken from the list L.”
Two immediate observations:
  • Python, this ain't.
  • My god, you have to read it right-to-left to follow the logic. Who thought that was a good idea?
Overall, so far it's a lot of boggling and wondering if someone deliberately wanted to do everything "the other way around."

Leaving for British Columbia tomorrow to spend the holidays with my wife's extended family (sharing a small house with two infants included). Wish me lots of patience. ;)


skvidal said...

Does reading right to left mean you need to take up japanese, too? Enjoy BC, take pictures if you get a chance. Some of us poor americans would like to see the exotic lands of our rich neighbors to the north.

Unknown said...

Compare to common mathematical notation for sets:

{ 2*x | x \in L }

doesn't seem to be too far off, if you ignore the annoying shuffling of all symbols...

Unknown said...


[2*X for X in L]

The symbols may be different, but the similarities are there.

Until you get to message-passing, of course.