I think it is appropriate that the first entry of this blog be the obligatory Hello World example. In keeping with this tradition, I would like to do the Hello World example in a language that is relatively new to me, Erlang.

While doing some basic research on the syntax of Erlang, I came across this great hello world example. I am going to post the code that I used below, but it is taken pretty much verbatim from that blog entry. The entry includes an excellent explanation of the actor model and the immutability of Erlang variables.

Another site of interest that I found during my search was called Learn You Some Erlang for great good. I have not had the opportunity to delve too deep, but it seems like a rational introduction to Erlang including its pros and cons.

There is one additional thing that the author of the real Erlang hello world left out, and I can understand why. It is only for people, like myself, who are very new to Erlang. The omission is to ensure that the filename is the same as the module name, but with the .erl extension. If you neglect this step, you will receive compiler errors.

%% This is how you do a single line comment in Erlang
-module(hello).
-export([start/0]).

start() ->
	spawn(fun() -> loop() end).

loop() ->
	receive
		hello ->
			io:format("Hello, World!~n"),
			loop();

		goodbye ->
			ok
	end.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s