<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Federico Feroldi's blog &#187; Erlang</title>
	<atom:link href="http://www.pixzone.com/blog/category/erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pixzone.com/blog</link>
	<description>by Federico Feroldi</description>
	<lastBuildDate>Sat, 13 Jun 2009 20:00:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Programming fun with Facebook Programming Puzzles</title>
		<link>http://www.pixzone.com/blog/236/programming-fun-with-facebook-programming-puzzles/</link>
		<comments>http://www.pixzone.com/blog/236/programming-fun-with-facebook-programming-puzzles/#comments</comments>
		<pubDate>Wed, 11 Jul 2007 09:16:33 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/236/programming-fun-with-facebook-programming-puzzles/</guid>
		<description><![CDATA[While looking around the Facebook developers docs I&#8217;ve found a page called Programming Puzzles. Basicaly if you want to work for Facebook you better try to solve some of these puzzles with one or more of the suggested languages and send the source code along with your resume. Next week after my university final exams [...]]]></description>
			<content:encoded><![CDATA[<p>While looking around the Facebook developers docs I&#8217;ve found a page called <a href="http://www.facebook.com/jobs_puzzles/">Programming Puzzles</a>. Basicaly if you want to <a href="http://www.facebook.com/jobs_engineering.php">work for Facebook</a> you better try to solve some of these puzzles with one or more of the suggested languages and send the source code along with your resume.<br />
Next week after my university final exams I&#8217;ll try to solve some of them in Erlang and Ruby, in the meantime <a href="http://www.facebook.com/jobs_puzzles/">have a look</a> and try yourself. <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/236/programming-fun-with-facebook-programming-puzzles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programmare in Erlang su Computer Programming (in edicola)</title>
		<link>http://www.pixzone.com/blog/230/programmare-in-erlang-su-computer-programming-in-edicola/</link>
		<comments>http://www.pixzone.com/blog/230/programmare-in-erlang-su-computer-programming-in-edicola/#comments</comments>
		<pubDate>Sun, 03 Jun 2007 19:10:35 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Nimboo]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/230/programmare-in-erlang-su-computer-programming-in-edicola/</guid>
		<description><![CDATA[Su Computer Programming di Gennaio il primo dei tre articoli di Federico Feroldi su Erlang, il linguaggio funzionale sviluppato da Ericsson.]]></description>
			<content:encoded><![CDATA[<p><img src="http://online.infomedia.it/immagini/riviste/covers/cp/cp169sm.jpg" align="right">Annuncio con immenso piacere che sul <a href="http://webonline.gruppoinfomedia.it/dac/index.php?form_rivista=cp&#038;form_rivistanum=169">numero di Giugno di Computer Programming</a> potete trovare il primo dei miei tre articoli su <a href="http://www.erlang.org/">Erlang</a>. In questo numero ho trattato principalmente la parte sintattica del linguaggio, facendo qualche esempio e introducendo il lettore alla programmazione funzionale. Correte in edicola! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><em>Translation for all the non-italian readers</em>: in the June issue of Computer Programming, the leading italian programming magazine, you can find the first of three articles I wrote about Erlang. It&#8217;s a great introduction to the language, so if you have an italian friend who wants to know more about this language, tell him to buy the magazine! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/230/programmare-in-erlang-su-computer-programming-in-edicola/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Erlang, Ruby and PHP battle it out!</title>
		<link>http://www.pixzone.com/blog/226/erlang-ruby-and-php-battle-it-out/</link>
		<comments>http://www.pixzone.com/blog/226/erlang-ruby-and-php-battle-it-out/#comments</comments>
		<pubDate>Sat, 19 May 2007 10:35:06 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Nimboo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/226/erlang-ruby-and-php-battle-it-out/</guid>
		<description><![CDATA[Yesterday I&#8217;ve been at the PHPDay 2007 in Verona with my Nimboo friend Giovanni Intini, during the travel to Verona on the train, we played with Erlang, Ruby and PHP writing small programs to compute Pythagorean triplets and comparing performances. I don&#8217;t want to tell you yet who&#8217;s the winner, you will find the results [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I&#8217;ve been at the PHPDay 2007 in Verona with my <a href="http://www.nimboo.net/">Nimboo</a> friend <a href="http://tempe.st/">Giovanni Intini</a>, during the travel to Verona on the train, we played with Erlang, Ruby and PHP writing small programs to compute <a href="http://en.wikipedia.org/wiki/Pythagorean_triple">Pythagorean triplets</a> and comparing performances.<br />
I don&#8217;t want to tell you yet who&#8217;s the winner, you will find the results of our tests in <a href="http://tempe.st/2007/05/erlang-ruby-and-php-battle-it-out/">Giovanni&#8217;s blog</a>.</p>
<p><em>Update: the <a href="http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/">battle continues here</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/226/erlang-ruby-and-php-battle-it-out/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Spell corrector (aka Google suggest) in Erlang (first iteration)</title>
		<link>http://www.pixzone.com/blog/223/spell-corrector-aka-google-suggest-in-erlang-first-part/</link>
		<comments>http://www.pixzone.com/blog/223/spell-corrector-aka-google-suggest-in-erlang-first-part/#comments</comments>
		<pubDate>Sun, 13 May 2007 22:16:25 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/223/spell-corrector-aka-google-suggest-in-erlang-first-part/</guid>
		<description><![CDATA[Spell corrector (aka Google suggest) in Erlang]]></description>
			<content:encoded><![CDATA[<p>After seeing the <a href="http://www.norvig.com/">Peter Norvig</a>&#8216;s implementation of a <a href="http://www.norvig.com/spell-correct.html">Spell corrector in 20 lines of python code</a>, I would like to add an Erlang implementation to the <a href="http://www.riffraff.info/2007/5/10/a-spell-corrector-in-perl6-part-1">perl6 one made by Gabriele</a>.</p>
<p><span style="text-decoration:line-through">Unfortunately I&#8217;m blocked by an issue I&#8217;m still trying to solve.</span> <em>(update: thanks to your suggestions I&#8217;ve solved the &#8220;folding&#8221; issue)</em></p>
<p>Here&#8217;s what I did until now:</p>
<p><em>(Note: I followed Peter Norvig&#8217;s naming for functions as much as possible.)</em></p>
<p>The <em>words/1</em> function takes a binary representation of the <a href="http://www.norvig.com/big.txt">reference text file</a> and build a list of words:</p>
<pre>
words(Bin) ->
    {ok, Words} = regexp:split(binary_to_list(Bin), "[^a-zA-Z]"),
    lists:map(fun(X) -> string:to_lower(X) end, Words).
</pre>
<p>The <em>train/1</em> function takes a list of words and creates a Set of lower case words with associated frequency:</p>
<pre>
train(Words) ->
    Dict = ets:new(dictionary, [set]),
    lists:foreach(fun(X) ->
        case ets:insert_new(Dict, {list_to_binary(X), 1}) of
            false -> ets:update_counter(Dict, list_to_binary(X), 1);
            true -> true
        end
    end, Words),
    Dict.
</pre>
<p>And finally the <em>build_dict/1</em> function takes a filename and returns the associated word Set:</p>
<pre>
build_dict(Filename) ->
    {ok, Bin} = file:read_file(Filename),
    train(words(Bin)).
</pre>
<p>Then there&#8217;s the function that generates all the possible &#8220;mistakes&#8221; from a word. This function is actually made of four different functions that generates different kind of errors:</p>
<pre>
alphabet() ->
    "abcdefghijklmnopqrstuvwxyz".

deletion_edits(Word) ->
    deletion_edits([], Word, []).
deletion_edits(_, [], Edits) ->
    Edits;
deletion_edits(Before, [Current | After], Edits) ->
	deletion_edits([Current | Before], After,
		[lists:reverse(Before) ++ After | Edits]).

transposition_edits(Word) ->
    transposition_edits([], Word, []).
transposition_edits(_, [], Edits) ->
    Edits;
transposition_edits(_, [_], Edits) ->
    Edits;
transposition_edits(Before, [Current, Next | After], Edits) ->
	transposition_edits([Current | Before], [Next | After],
		[ lists:reverse(Before) ++ [Next, Current] ++ After | Edits]).

alteration_edits(Word) ->
    alteration_edits([], Word, []).
alteration_edits(_, [], Edits) ->
    Edits;
alteration_edits(Before, [Current | After], Edits) ->
	BeforeR = lists:reverse(Before),
	alteration_edits([Current | Before], After,
		[BeforeR ++ [X] ++ After || X <- alphabet()] ++ Edits).

insertion_edits(Word) ->
    insertion_edits([], Word, [[X] ++ Word || X <- alphabet()]).
insertion_edits(_, [], Edits) ->
    Edits;
insertion_edits(Before, [Current | After], Edits) ->
	BeforeR = lists:reverse(Before),
	insertion_edits([Current | Before], After,
		[BeforeR ++ [Current, X] ++ After || X <- alphabet()] ++
		Edits).
</pre>
<p>We have <em>edits1/1</em> that generates the 1-level error words and <em>edits1/2</em> that generates the 2-level (errors of errors) words:</p>
<pre>
edits1(Word) ->
    lists:usort(deletion_edits(Word) ++ transposition_edits(Word) ++ alteration_edits(Word) ++ insertion_edits(Word)).
</pre>
<pre>
edits2(Word) ->
	lists:usort(lists:foldr(fun(A, AccIn) ->
		AccIn ++ edits1(A)
	end, [], edits1(Word))).
</pre>
<p><span style="text-decoration:line-through">The problem is on the <em>edits2/1</em> function, it generates a list made of sublists but I want it to generate a single flat list instead. I've tryed <em>lists:flatten/1</em> but it flattens strings too, I need time to find the correct function...</span></p>
<p>Here's the <em>known/2</em> function that filters a list of words by returning only the words present in the dictionary:</p>
<pre>
known(Words, Dict) ->
	lists:filter(fun(Word) ->
		ets:member(Dict, list_to_binary(Word))
	end, Words).
</pre>
<p>And then there's the <em>gen_candidates/2</em> function that generates the possible correct words from the mispelled one:</p>
<pre>
gen_candidates(Word, Dict) ->
	C1 = known([Word], Dict),
	case (length(C1) > 0) of
		true ->
			[Word];
		false ->
			C2 = known(edits1(Word), Dict),
			case (length(C2) > 0) of
				true ->
					C2;
				false ->
					C3 = known(edits2(Word), Dict),
					case (length(C3) > 0) of
						true -> C3;
						false -> [Word]
					end
			end
	end.
</pre>
<p>And finally the <em>correct/2</em> function that takes a mispelled word and returns the most probable correct one:</p>
<pre>
correct(Word, Dict) ->
	lists:foldl(fun(W, {CN, CW}) ->
		case ets:lookup(Dict, list_to_binary(W)) of
			[{LW, LN}] ->
				case LN > CN of
					true -> {LN, LW};
					false -> {CN, CW}
				end;
			_ ->
				{CN, CW}
		end
	end, {0, Word}, gen_candidates(Word, Dict)).
</pre>
<p>At this point I started trying some words on the shell:</p>
<pre>
5> Dict = spellcheck:build_dict("big.txt").
14
6> spellcheck:known(["hello", "helo"], Dict).
["hello"]
7> spellcheck:known(["hello", "helo", "true"], Dict).
["hello","true"]
8> spellcheck:gen_candidates("hello", Dict).
["hello"]
9> spellcheck:gen_candidates("helo", Dict).
["felo","halo","held","hell","hello","helm","help","hero"]
10> spellcheck:correct("helo", Dict).
{287,<<"held">>}
11> spellcheck:correct("correctz", Dict).
{38,<<"correct">>}
12> spellcheck:correct("correc", Dict).
{38,<<"correct">>}
13> spellcheck:correct("gues", Dict).
{112,<<"guns">>}
14> spellcheck:correct("guess", Dict).
{17,<<"guess">>}
15> spellcheck:correct("gues", Dict).
{112,<<"guns">>}
16> spellcheck:correct("gue", Dict).
{249,<<"due">>}
</pre>
<p>It seems to work! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>In the next iteration I'll try to optimize and refactor the code, in special way for the edits generators that are too long for my tastes... Suggestions are welcome! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/223/spell-corrector-aka-google-suggest-in-erlang-first-part/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to build a POP3 to RSS gateway in Erlang</title>
		<link>http://www.pixzone.com/blog/222/how-to-build-a-pop3-to-rss-gateway-in-erlang/</link>
		<comments>http://www.pixzone.com/blog/222/how-to-build-a-pop3-to-rss-gateway-in-erlang/#comments</comments>
		<pubDate>Wed, 09 May 2007 17:36:51 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/222/how-to-build-a-pop3-to-rss-gateway-in-erlang/</guid>
		<description><![CDATA[How to build a POP3 to RSS gateway in Erlang, talks about concurrent and socket programming.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.stifflog.com/aboutme.html">JarosÅ‚aw RzeszÃ³tko</a> wrote this great article where he builds a <a href="http://www.stifflog.com/2007/05/09/erlang-for-the-practical-man/">POP3 to RSS gateway in Erlang</a>. Very nice stuff and well written article on the topic. He&#8217;s also running for the <a href="http://on-erlang.blogspot.com/2007/05/may-blogging-contest.html">Erlang blogging contest</a> and I&#8217;m sure he has good chances to win!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/222/how-to-build-a-pop3-to-rss-gateway-in-erlang/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Erlang data types (Lesson 2)</title>
		<link>http://www.pixzone.com/blog/220/erlang-data-types-lesson-2/</link>
		<comments>http://www.pixzone.com/blog/220/erlang-data-types-lesson-2/#comments</comments>
		<pubDate>Mon, 07 May 2007 17:21:13 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/220/erlang-data-types-lesson-2/</guid>
		<description><![CDATA[The first thing you should learn about a new language is about its small bricks, the <strong>data types</strong>. Once you know how to structure your data, you can build your application on it. So, let's take a brief look on Erlang's data types in this article.]]></description>
			<content:encoded><![CDATA[<p>The first thing you should learn about a new language is its small bricks, the <strong>data types</strong>. Once you know how to structure your data you can build your application on it.<br />
So, let&#8217;s take a brief look at Erlang&#8217;s data types.</p>
<h3>Numbers</h3>
<p>Erlang supports integer and floating point numbers. Integer numbers can have almost unlimited size. Try this on the Erlang shell (<em>erl</em>):<br />
<code><br />
2> 4534535*543636345*3445343*6564574523432.<br />
55754546761558695184405188371500200<br />
</code><br />
You can also have floating point numbers, but they have limited precision and size:<br />
<code><br />
3> 3 / 2.<br />
1.50000<br />
4> 2 * 1.5.<br />
3.00000<br />
</code></p>
<h3>Strings</h3>
<p>Strings are made of quoted text like <em>&#8220;This is a String!&#8221;</em>. Erlang deals with strings as they were lists of characters. Unfortunately when Erlang was born, his father didn&#8217;t knew about Unicode, so we can just have Latin-1 characters (ASCII 0-255) so far.</p>
<h3>Atoms</h3>
<p>Atoms are <em>names</em>, constant text strings that you can use like C&#8217;s enums or Ruby&#8217;s symbols.<br />
Atoms must be unquoted alphanumeric strings that begins with a lower case letter. You can also have non alphanumeric atoms that begins with any letter by quoting the string with a single quote.<br />
Examples: <em>apple</em>, <em>mice</em>, <em>dog</em>, <em>banana</em>, <em>&#8216;Valentina&#8217;</em>, <em>&#8216;This is an Atom!&#8217;</em>.</p>
<h3>Tuples</h3>
<p>Tuples are fixed sets of data. You cannot add anything to a tuple once you created it. Tuples can contain other tuples, atom, strings and lists.<br />
Examples: <em>{this, is, &#8220;a tuple&#8221;, with, 6, &#8216;Elements!&#8217;}</em>, <em>{1 + 2, milk, banana, [ 1, 2, 3 ]}</em>.</p>
<h3>Lists</h3>
<p>Lists are similar to tuples but they can contain an undefined amount of items of any type:<br />
<code><br />
10> [1, 2, 3, {this, is, a, tuple}, anatom, [a, list]].<br />
[1,2,3,{this,is,a,tuple},anatom,[a,list]]<br />
</code><br />
It&#8217;s also very easy to split a list into his <em>head</em> and his <em>tail</em>, and that&#8217;s also the only way to access his elements (you cannot extract the <em>nth</em> element before the <em>nth-1</em> elements):<br />
<code><br />
11> [Head | Tail] = [a, b, c, d].<br />
[a,b,c,d]<br />
12> Head.<br />
a<br />
13> Tail.<br />
[b,c,d]<br />
</code><br />
You can also create new lists by adding elements in front or at the end of an existing one:<br />
<code><br />
14> [1, 2, 3 | Tail].<br />
[1,2,3,b,c,d]<br />
15> [Head|[1,2,3]].<br />
[a,1,2,3]<br />
</code></p>
<h3>Funs</h3>
<p>Last but not least we have <em>funs</em> that are anonymous functions. Erlang deals with funs as they were like any other data type. You can assign funs to variables, pass funs to as parameter to function calls and return funs as function results:<br />
<code><br />
15> MyFun = fun(X) -> X * 2 end.<br />
#Fun<erl_eval.6.72228031><br />
16> MyFun(5).<br />
10<br />
17> lists:map(MyFun, [1, 2, 3]).<br />
[2,4,6]<br />
</code></p>
<p>That&#8217;s all for now! I hope to have made less mistakes than the last time! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/220/erlang-data-types-lesson-2/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Buy Computer Programming magazine to learn Erlang</title>
		<link>http://www.pixzone.com/blog/219/buy-computer-programming-magazine-to-learn-erlang/</link>
		<comments>http://www.pixzone.com/blog/219/buy-computer-programming-magazine-to-learn-erlang/#comments</comments>
		<pubDate>Wed, 02 May 2007 22:29:17 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/219/buy-computer-programming-magazine-to-learn-erlang/</guid>
		<description><![CDATA[A Computer Programming article about introduction to Erlang language, sequential programming, list management, concurrent and distributed programming.]]></description>
			<content:encoded><![CDATA[<p><img align="right" src="http://www.infomedia.it/immagini/riviste/covers/cp/cp167sm.jpg" alt="Computer Programming" />I&#8217;ve been a little busy in the past couple days, I was writing two articles for what I consider the most important italian programming magazine: <a href="http://www.infomedia.it/riviste/cp/cp.htm">Computer Programming</a>. I remember when more than 15 years ago I bought the 1st issue of CP and I started learning how to program 8086 assembly. Ahhh, great times&#8230; <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Anyway, these two articles will be probably published in the next months issues. The first one is an <strong>introduction to Erlang language and features</strong> and the second one talks more in deep about <strong>list management and advanced stuff like anonymous functions and lists comprehensions</strong>.<br />
During the next month I&#8217;ll write one or two more of them on the most interesting topics like <strong>concurrent and distributed programming</strong>.<br />
I hope to spread the Erlang verb a little more! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/219/buy-computer-programming-magazine-to-learn-erlang/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Your first Erlang program in less than 1 minute! (Lesson 1)</title>
		<link>http://www.pixzone.com/blog/218/youre-first-erlang-program-in-less-than-1-minute-lesson-1/</link>
		<comments>http://www.pixzone.com/blog/218/youre-first-erlang-program-in-less-than-1-minute-lesson-1/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 11:50:26 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/218/youre-first-erlang-program-in-less-than-1-minute-lesson-1/</guid>
		<description><![CDATA[Begin to learn Erlang programming starting from a small Erlang program. It just takes you less than a minute!]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s what it takes to write an Hello World program in Erlang, after you installed the <a href="http://www.erlang.org/download.html">Erlang system</a> on your machine.</p>
<p>Here&#8217;s the program itself:<br />
<code><br />
<span><span class="S6">-</span><span class="S4">module</span><span class="S6">(</span><span class="S7">hello</span><span class="S6">).</span><br />
<span class="S6">-</span><span class="S4">export</span><span class="S6">([</span><span class="S8">hello_world/0</span><span class="S6">]).</span></p>
<p><span class="S7">hello_world</span><span class="S6">()-&gt;</span><br />
<span class="S0">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="S7">io</span><span class="S6">:</span><span class="S7">format</span><span class="S6">(</span><span class="S5">"Hello World ~n"</span><span class="S6">).</span><span class="S0"> </span></span><br />
</code></p>
<p>What does that means? Briefly:</p>
<dl>
<p><di></p>
<dt><span><span class="S6">-</span><span class="S4">module</span><span class="S6">(</span><span class="S7">hello</span><span class="S6">).</span></dt>
<dd>Create a module for the following functions, think of it like a namespace declaration.</dd>
<p></di></p>
<p><di></p>
<dt><span class="S6">-</span><span class="S4">export</span><span class="S6">([</span><span class="S8">hello_world/0</span><span class="S6">]).</span></dt>
<dd>This tells the compiler that we want to export the <code>hello_world/0</code> function to the outer world. It means the other modules can call this function. What does the &#8220;/0&#8243; means? It means the &#8220;hello_world&#8221; function with 0 parameters. In Erlang, you can have different functions with the same name and different number of parameters.</dd>
<p></di></p>
<p><di></p>
<dt><span class="S7">hello_world</span><span class="S6">()-&gt;</span></dt>
<dd>Declare a new function named &#8220;hello_world&#8221; that accept no parameters, the body will follow the arrow.</dd>
<p></di></p>
<p><di></p>
<dt><span class="S0">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="S7">io</span><span class="S6">:</span><span class="S7">format</span><span class="S6">(</span><span class="S5">&#8220;Hello World ~n&#8221;</span><span class="S6">).</span><span class="S0"> </span></span></dt>
<dd>This calls the &#8220;format&#8221; function from the module &#8220;io&#8221; that prints out the Hello World message. The &#8220;~n&#8221; characters prints the Carriage Return, the same as &#8220;/n&#8221; in other languages.</dd>
<p></di></p>
</dl>
<p>To run your program you must start the Erlang shell first:</p>
<p><code><br />
$ erl<br />
Erlang (BEAM) emulator version 5.5.4 [async-threads:0]<br />
Eshell V5.5.4  (abort with ^G)<br />
1> c(hello).<br />
{ok,hello}<br />
2> hello:hello_world().<br />
Hello World<br />
ok<br />
3><br />
</code></p>
<p>Try it, and understand it. Next time will be a little bit more complex! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Note: if you guess why by copying and pasting the code you get a lot of errors, that&#8217;s because <a href="http://www.scintilla.org/SciTE.html">SciTe</a>, the editor I use, exports the code with fancy double quotes. That&#8217;s a good reason to not being lazy and write the program by yourself! Writing it&#8217;s a nice way of learning! <img src='http://www.pixzone.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div style="float:right">
<script type="text/javascript">
digg_url = 'http://www.pixzone.com/blog/218/youre-first-erlang-program-in-less-than-1-minute-lesson-1/';
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/218/youre-first-erlang-program-in-less-than-1-minute-lesson-1/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Erlang helps Rails to scale</title>
		<link>http://www.pixzone.com/blog/217/erlang-helps-rails-to-scale/</link>
		<comments>http://www.pixzone.com/blog/217/erlang-helps-rails-to-scale/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 14:40:13 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/217/erlang-helps-rails-to-scale/</guid>
		<description><![CDATA[Maybe not yet, but it&#8217;s interesting to see that Erlang gets mentioned in the Scaling Twitter presentation. Apparently Twitter used the ejabberd Jabber/XMPP server as their instant messaging platform. They also mention RabbitMQ, an Enterprise-class messaging system built in Erlang, as a possible high performance platform for their message passing infrastructure.]]></description>
			<content:encoded><![CDATA[<p><img src="http://assets1.twitter.com/images/twitter.png?1177117570" align="right" /> Maybe not yet, but it&#8217;s interesting to see that <a href="http://www.erlang.org/">Erlang</a> gets mentioned in the <a href="http://www.slideshare.net/Blaine/scaling-twitter/">Scaling Twitter</a> presentation. Apparently <a href="http://www.twitter.com/">Twitter</a> used the <a href="http://ejabberd.jabber.ru/">ejabberd</a> Jabber/XMPP server as their instant messaging platform. They also mention <a href="http://www.rabbitmq.com/">RabbitMQ</a>, an <a href="http://www.rabbitmq.com/erlang.html">Enterprise-class messaging system built in Erlang</a>,  as a possible high performance platform for their message passing infrastructure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/217/erlang-helps-rails-to-scale/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>What&#8217;s all this fuss about Erlang?</title>
		<link>http://www.pixzone.com/blog/214/whats-all-this-fuss-about-erlang/</link>
		<comments>http://www.pixzone.com/blog/214/whats-all-this-fuss-about-erlang/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 16:09:22 +0000</pubDate>
		<dc:creator>Federico Feroldi</dc:creator>
				<category><![CDATA[Erlang]]></category>

		<guid isPermaLink="false">http://www.pixzone.com/blog/214/whats-all-this-fuss-about-erlang/</guid>
		<description><![CDATA[The future of Erlang and multi core cpu architectures by Joe Armstrong.]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://www.erlang.org/">Erlang</a> is gaining a lot of popularity, probably due to the publishing of the <a href="http://www.pragmaticprogrammer.com/titles/jaerlang">Programming Erlang</a> book from the <a href="http://www.pragmaticprogrammer.com/">Pragmatic Programmer</a>. In <a href="http://www.pragmaticprogrammer.com/articles/erlang.html">this article about the Erlang future</a>, <a href="http://www.sics.se/~joe/index.html">Joe Armstrong</a> explaing why Erlang Concurrency Oriented Programming will be much more important from now on, since we&#8217;re moving to a multi core processing era!</p>
<blockquote><p>
Nobody can predict the future, but I&#8217;m going to make a few informed guesses.</p>
<p>Let&#8217;s suppose Intel is right: let&#8217;s suppose that the Keifer project succeeds. If this happens, then 32 core processors will appear on the market as soon as 2009/2010.</p>
<p>This comes as no surprise; Sun already ships the Niagara with 8 cores running 4 hyperthreads per core (which is equivalent to 32 cores).</p>
<p>This is a development that makes Erlang programmers very happy. They have been waiting 20 years for this to happen, and now it&#8217;s payback time.</p>
<p>Here&#8217;s the good news for Erlang programmers:</p>
<p>    <strong>Your Erlang program should just run N times faster on an N core processor</strong>
</p></blockquote>
<p><!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixzone.com/blog/214/whats-all-this-fuss-about-erlang/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.866 seconds -->
<!-- Cached page served by WP-Cache -->
