/
2011-01-06-erlang-beginners-tutorial.html
65 lines (43 loc) · 4.11 KB
/
2011-01-06-erlang-beginners-tutorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
layout: post
title: "Erlang: For an absolute beginner"
date: 2011-01-06 22:42:04
categories: erlang code
---
<p>Last night I spent 30 minutes having a play with a new (to me) programming language, <a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)">Erlang</a>.</p>
<p>Its a language that will stretch my brain a bit, teach me to think about programming in a different way, and I know some folks using it (Mostly <a href="http://smarkets.com/">Smarkets</a> and <a href="http://irccloud.com">IRCCloud</a>) who’s brains I can pick in the pub.</p>
<p>These are my quick notes from an Erlang newbie, hopefully useful to someone else getting started who justs wants to install it, write Hello World and go from there.</p>
<h3>Installing Erlang on OSX</h3>
<p>This is incredibly easy with <a href="https://github.com/mxcl/homebrew">Homebrew</a> (a package manager for OSX). As simple as:</p>
<pre><code>brew install erlang</code></pre>
<p>I expect they’ll be some cases where I need more than that stock install, but it’s good enough to get started. I haven’t tried it on my server, but it looks like a simple apt-get should do the trick, rather than the ball-ache of compiling from source.</p>
<h3>Writing ‘Hello World’</h3>
<p>The <a href="http://www.erlang.org/faq/getting_started.html#id52506">Erlang FAQ</a> has the simplest example:</p>
<pre><code>
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("hello, world\n").
</code></pre>
<p>Save that as <code>hello.erl</code> (the name of the file needs to match the module name), run the Erlang shell (run <code>erl</code>) and compile it like so:</p>
<pre><code>
$ erl
1 > c(hello).
</code></pre>
<p>This will generate an Erlang bytcode file called <code>hello.beam</code> in your working directory. To run it, switch back to the Erlang shell and call the exported function on your module.</p>
<pre><code>
2 > hello:hello_world().
hello, world
ok
3 >
</code></pre>
<p>Simple. Thought i’d also recommend looking at a <a href="http://egarson.blogspot.com/2008/03/real-erlang-hello-world.html">more complicated ‘Hello World’</a> that is a more idiomatic and Erlang-y version, </p>
<h3>What next?</h3>
<p>I <a href="http://twitter.com/#!/dsingleton/status/22716268050124801">asked on Twitter</a> for some good Erlang resources, books, blogs, tutorials etc:</p>
<ul><li><a href="http://www.amazon.co.uk/gp/product/193435600X?ie=UTF8&tag=httpdsingleco-21&linkCode=as2&camp=1634&creative=19450&creativeASIN=193435600X">Joe Armstrong - Programming Erlang: Software for a Concurrent World</a>. A lot of very smart people recommend this, the classic book on Erlang by one of it’s creators. It’s going on my Kindle as I type.</li>
<li><a href="http://learnyousomeerlang.com/">learn you some Erlang</a>. A more approachable introduction to Erlang, with a little of <a href="http://en.wikipedia.org/wiki/Why_the_lucky_stiff">_why’s</a> style about it.</li>
<li><a href="http://www.delicious.com/dsingleton/erlang">My bookmarks tagged Erlang</a>. I’ll be adding more links as I collect them.</li>
</ul><p>I guess my next step is to pick a small project to building in Erlang. It always seems better to have a simple project to help pick up a language.</p>
<p>At the moment I think i’m going to work through some of the <a href="http://projecteuler.net/">Project Euler></a> problems and get to grips with the basics. Then perhaps build a toy web server, which has the added bonus of grokking more of the HTTP spec.</p>
<h3>And finally…</h3>
<p>It wouldn’t be a beginning Erlang blog post without the obligatory “<em>Hello Joe</em>" from the brilliant Erlang: The Movie</p>
<object width="480" height="385" data type><param name="movie" value="http://www.youtube.com/v/uKfKtXYLG78?fs=1&hl=en_US"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/uKfKtXYLG78?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385" /></object>