Day 27: Erlang
I’ve always been intimidated by Erlang; its syntax is just similar enough to languages I know that it seems like I should be able to read it, but different enough that I can’t. Undaunted, I installed it with Homebrew, loaded a few PDFs onto my laptop, and boarded the plane back to NC. I started off with the total idiot’s guide, which was just about right. It showed me how to use the interactive console and compile a basic program. From there, the official site provided a link to the Erlang/OTP System Documentation, but at 300 pages, it was a little dense for my purposes. Fortunately, I was able to find a link to Getting Started with Erlang (PDF), weighing in at a much more manageable 58 pages. I managed to work my way through about half the guide in an hour, and though it was last updated in ’04, I can testify that it does a fantastic job walking new users through the basics of Erlang.
I think this hour was the biggest success thus far. As I said before, I’ve looked at Erlang in the past, but was always too intimated to really dive in. This time, things were different, for three key reasons:
The fixed time window. There were times where got frustrated or reached natural stopping points, but I forced myself to keep pushing to fill out the entire hour.
Knowing how to learn. I’ve developed a much better sense for how I learn best. None of the current docs really hit that sweet spot for me, so I dug around until I found a guide that really suits me, using interactive code examples that build on themselves as they increase in complexity.
Understanding language patterns. Jumping into Erlang from a strictly object-oriented programming background would have confused and bewildered me. Because of my experiences in the last month though, I was much more able to indentify language features. Specifically, Erlang’s pattern matching is very similar to that of OCaml, and the idiom of assigning variables to the head and tail of a list, doing something to the head, and then recursing with the tail is straight out of The Little Schemer.
Here’s my Erlang fold:
-module(fold).
-export([fold/2, fold/3]).
fold([First | Rest], Fun) ->
fold(Rest, Fun, First);
fold([], Fun) ->
[].
fold([First | Rest], Fun, Result) ->
fold(Rest, Fun, Fun(Result, First));
fold([], Fun, Result) ->
Result.
% 10> fold:fold([1,2,3], fun(Sum, Item) -> Sum + Item end).
% 6
I’m feeling really encouraged by this experience. This is the first time where I’ve felt this month has reaped rewards above and beyond learning the individual technologies, and just in time for me to put together my DevNation Chicago talk. Now: onto Haskell before my battery gives out.