<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Erlang Examples</title>
	
	<link>http://erlangexamples.com</link>
	<description>Diving into Erlang World</description>
	<lastBuildDate>Fri, 30 Apr 2010 15:37:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ErlangExamples" /><feedburner:info uri="erlangexamples" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Building Erlang B13R04 in CentOS 5.4</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/Xo8NCuoaxOw/</link>
		<comments>http://erlangexamples.com/2010/04/30/building-erlang-b13r04-in-centos-5-4/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 15:36:34 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Installation]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[OTP]]></category>
		<category><![CDATA[r13b04]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=105</guid>
		<description><![CDATA[Last post was about building Erlang B13R04 in Ubuntu. For CentOS, it&#8217;s somehow the same with yum sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel wget http://www.erlang.org/download/otp_src_R13B04.tar.gz tar xfvz otp_src_R13B04.tar.gz cd otp_src_R13B04/ ./configure --with-ssl sudo make install However, I haven&#8217;t found the similar package to xsltproc and fop yet. But it&#8217;s only [...]]]></description>
			<content:encoded><![CDATA[<p>Last post was about <a href="http://erlangexamples.com/2010/04/05/building-erlang-b13r04-in-ubuntu-9-10-karmic/">building Erlang B13R04 in Ubuntu</a>. For CentOS, it&#8217;s somehow the same with <strong>yum</strong><br />
<code><br />
sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel<br />
wget http://www.erlang.org/download/otp_src_R13B04.tar.gz<br />
tar xfvz otp_src_R13B04.tar.gz<br />
cd otp_src_R13B04/<br />
./configure --with-ssl<br />
sudo make install<br />
</code><br />
However, I haven&#8217;t found the similar package to <strong>xsltproc</strong> and <strong>fop</strong> yet. But it&#8217;s only for building the documentation which I don&#8217;t really need.</p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/Xo8NCuoaxOw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2010/04/30/building-erlang-b13r04-in-centos-5-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2010/04/30/building-erlang-b13r04-in-centos-5-4/</feedburner:origLink></item>
		<item>
		<title>Building Erlang B13R04 in Ubuntu 9.10 Karmic</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/h-o5WHlhxF4/</link>
		<comments>http://erlangexamples.com/2010/04/05/building-erlang-b13r04-in-ubuntu-9-10-karmic/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 14:03:14 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Installation]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[karmic]]></category>
		<category><![CDATA[OTP]]></category>
		<category><![CDATA[rebar]]></category>
		<category><![CDATA[riak]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=100</guid>
		<description><![CDATA[Frankly speaking, I always use apt-get to install Erlang rather than building from source&#8230; lazy huh? Unfortunately, when I apt-get in Ubuntu 9.10 Karmic, only Erlang/OTP R13B01 (5.7.2) is available whereas the latest is R13B04 (5.7.5) which is required to build Riak (actually rebar requires 5.7.4 and above)&#8230; It takes around 10-15 min to build, [...]]]></description>
			<content:encoded><![CDATA[<p>Frankly speaking, I always use apt-get to install Erlang rather than building from source&#8230; lazy huh? Unfortunately, when I apt-get in Ubuntu 9.10 Karmic, only Erlang/OTP R13B01 (5.7.2) is available whereas the latest is R13B04 (5.7.5) which is required to build <a title="Riak" href="http://riak.basho.com" target="_blank">Riak</a> (actually <a title="rebar" href="http://bitbucket.org/basho/rebar/" target="_blank">rebar</a> requires 5.7.4 and above)&#8230;</p>
<p>It takes around 10-15 min to build, and these are the required libraries and dependencies</p>
<pre>sudo apt-get install build-essential m4 libncurses5-dev libssl-dev xsltproc fop
axel -n 20 http://www.erlang.org/download/otp_src_R13B04.tar.gz
tar xfvz otp_src_R13B04.tar.gz
cd otp_src_R13B04/
./configure --with-ssl
sudo make install</pre>
<p>Here i&#8217;m using <strong>axel</strong> for fast download, it&#8217;s your choice to use <strong>curl</strong> or <strong>wget</strong>.</p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/h-o5WHlhxF4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2010/04/05/building-erlang-b13r04-in-ubuntu-9-10-karmic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2010/04/05/building-erlang-b13r04-in-ubuntu-9-10-karmic/</feedburner:origLink></item>
		<item>
		<title>OneTeam Media Server and Erling</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/P5zK77uEoG8/</link>
		<comments>http://erlangexamples.com/2010/03/29/oneteam-media-server-and-erling/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 06:59:21 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[AMF]]></category>
		<category><![CDATA[erling]]></category>
		<category><![CDATA[media server]]></category>
		<category><![CDATA[oms]]></category>
		<category><![CDATA[processone]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=98</guid>
		<description><![CDATA[It&#8217;s been a long time I haven&#8217;t blogged anything about erlang &#8230; damn&#8230; too many cool stuff but too little time. Actually my works are getting heavily busy these days + 4-month-old kid &#8230; lots of excuses huh? Good news is I&#8217;ve been back to my Erling (AMF Implementation) recently. While spending sometimes to see [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time I haven&#8217;t blogged anything about erlang &#8230; damn&#8230; too many cool stuff but too little time. Actually my works are getting heavily busy these days + 4-month-old kid &#8230; lots of excuses huh?</p>
<p>Good news is I&#8217;ve been back to my <a href="http://github.com/trung/erling">Erling (AMF Implementation) </a>recently. While spending sometimes to see what progress I have made so far, I came across <a href="http://www.process-one.net/en/blogs/article/oneteam_media_server_by_processone/">OMS (OneTeam Media Server)</a> release announcement.</p>
<blockquote><p>OneTeam Media Server, or OMS for short, is a new Flash server implementation, written in erlang, by ProcessOne. This will enable your users to broadcast voice and/or video streams to multiple subscribers.</p>
</blockquote>
<p>Wow, this is a great news &#8230; it&#8217;s greater to see more and more heavy task back-end services written in Erlang. I&#8217;ve registered an account with <a href="https://git.process-one.net/">ProcessOne Git Repository</a> just to fork the project. Lots of thing can learn from OMS. Many thanks to ProcessOne for open source this project.</p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/P5zK77uEoG8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2010/03/29/oneteam-media-server-and-erling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2010/03/29/oneteam-media-server-and-erling/</feedburner:origLink></item>
		<item>
		<title>Record introspection at compile time</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/ZXWvM7pBamA/</link>
		<comments>http://erlangexamples.com/2009/10/08/record-introspection-at-compile-time/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 02:22:59 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[AMF]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[Record]]></category>
		<category><![CDATA[autogenerate]]></category>
		<category><![CDATA[instrospection]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=86</guid>
		<description><![CDATA[For AMF implementation, I have to define the mapping between Actionscript classes with something equivalent in Erlang. First thing came into my mind is record. However, I immediately encountered some of the difficulties when using records in Erlang Read: can&#8217;t use reflection easily after parsing AMF, I received the object with properties/values and I need [...]]]></description>
			<content:encoded><![CDATA[<p>For <a href="http://github.com/trung/erling">AMF implementation</a>, I have to define the mapping between Actionscript classes with something equivalent in Erlang. First thing came into my mind is <a href="http://erlangexamples.com/2009/03/09/how-to-create-and-manipulate-records/">record</a>. However, I immediately encountered some of the difficulties when using records in Erlang</p>
<ol>
<li> <strong>Read:</strong> can&#8217;t use reflection easily after parsing AMF, I received the object with properties/values and I need to map to the corresponding record</li>
<li> <strong>Write:</strong> Need to introspect the record and write its properties into binaries</li>
</ol>
<p>I found <a href="http://www.trapexit.org/Match_Specifications_And_Records_(Dynamically!)/">this post</a> from <a href="http://www.trapexit.org">trapexit</a>. However, I need specifically more than that. </p>
<p>Normally records are defined in a header file &#8220;.hrl&#8221;. And the idea is to generate utility codes (getter, setter, record meta data &#8230;.) at compile time. The heart of it is <a href="http://www.erlang.org/doc/man/epp.html">epp:parse_file/3</a> function. The generator (or the helper) reads header files, parses all records and create a compilable .erl file which contains all functions you need to do all magic with records:</p>
<ol>
<li>set(Obj, PropertyName, Value) -> {ok, NewObj, {PropertyName, Value}}</li>
<li>get(Obj, PropertyName) -> {ok, Value}</li>
<li>fields(record_name) -> Fields = [string()]</li>
<li>fields_atom(record_name) -> Fields = [term()]</li>
<li>type(Obj) -> record_name</li>
</ol>
<p><strong>messages.hrl</strong> &#8211; the source<br />
<script src="http://gist.github.com/215656.js"></script><br />
<strong>record_helper.erl</strong> &#8211; the generator<br />
<script src="http://gist.github.com/215658.js"></script><br />
<strong>record_utils.erl</strong> &#8211; the generated source<br />
<script src="http://gist.github.com/215665.js"></script><br />
Below is the demonstration of how to generate and use the record utils</p>
<pre class="console">
1> c(record_helper.erl).
{ok,record_helper}
2> record_helper:make(["messages.hrl"], ".").
ok
3> ls().
messages.hrl            record_helper.beam
record_helper.erl      record_utils.erl
ok
6> c(record_utils).
{ok,record_utils}
7> rr("messages.hrl").
[abstract_message,async_message]
8> Obj = #async_message{}.
#async_message{
    parent =
        #abstract_message{
            clientId = undefined,destination = undefined,
            messageId = undefined,timestamp = undefined,
            timeToLive = undefined,headers = undefined,body = undefined},
    correlationId = undefined,correlationIdBytes = undefined}
9> record_utils:set(Obj, correlationId, "ADF-123-DDF-543").
{ok,#async_message{
        parent =
            #abstract_message{
                clientId = undefined,destination = undefined,
                messageId = undefined,timestamp = undefined,
                timeToLive = undefined,headers = undefined,body = undefined},
        correlationId = "ADF-123-DDF-543",
        correlationIdBytes = undefined},
    {correlationId,"ADF-123-DDF-543"}}
10> {ok,NewObj, _} = record_utils:set(Obj, correlationId, "ADF-123-DDF-543").
{ok,#async_message{
        parent =
            #abstract_message{
                clientId = undefined,destination = undefined,
                messageId = undefined,timestamp = undefined,
                timeToLive = undefined,headers = undefined,body = undefined},
        correlationId = "ADF-123-DDF-543",
        correlationIdBytes = undefined},
    {correlationId,"ADF-123-DDF-543"}}
11> record_utils:get(NewObj, correlationId).
{ok,"ADF-123-DDF-543"}
12> record_utils:type(NewObj).
async_message
</pre>
<p>record_helper.erl is not so clean as there&#8217;re all string concatenations &#8230; further improvements can be:</p>
<ol>
<li>Using template language like <a href="http://code.google.com/p/erlydtl/">ErlyDTL</a> or <a href="http://yarivsblog.com/articles/2006/10/17/introducting-erltl-a-simple-erlang-template-language/">ErlTL</a> &#8230;</li>
<li>Clean up code to have more friendly arguments</li>
<li>You add &#8230;.</li>
</ol>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/ZXWvM7pBamA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/10/08/record-introspection-at-compile-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/10/08/record-introspection-at-compile-time/</feedburner:origLink></item>
		<item>
		<title>amf implementation using Erlang</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/jIen1Q_IxU4/</link>
		<comments>http://erlangexamples.com/2009/10/04/amf-implementation-using-erlang/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 01:26:55 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[AMF]]></category>
		<category><![CDATA[erling]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=84</guid>
		<description><![CDATA[I just restarted a long sleep idea to implement AMF using Erlang, the project, codenamed Erling, is hosted in github. There&#8217;s nothing much yet except amf0 and amf3 implementation, i&#8217;m working on the unit test for whatever I&#8217;ve written so far to make sure it won&#8217;t go messy as the code evolved. Everyday I&#8217;m learning [...]]]></description>
			<content:encoded><![CDATA[<p>I just restarted a long sleep idea to implement AMF using Erlang, <a href="http://github.com/trung/erling">the project, codenamed Erling, is hosted in github</a>. There&#8217;s nothing much yet except amf0 and amf3 implementation, i&#8217;m working on the unit test for whatever I&#8217;ve written so far to make sure it won&#8217;t go messy as the code evolved.<br />
Everyday I&#8217;m learning new thing along with Erling and therefore more Erlang examples to come &#8230;</p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/jIen1Q_IxU4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/10/04/amf-implementation-using-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/10/04/amf-implementation-using-erlang/</feedburner:origLink></item>
		<item>
		<title>Date time manipulation howtos</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/-26_ym1S9ok/</link>
		<comments>http://erlangexamples.com/2009/09/06/date-time-manipulation-howtos/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 05:03:14 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[manipulation]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=76</guid>
		<description><![CDATA[Erlang offers calendar module which provides computation of date, time and number of date time conversion functions. For more details, please refer to documentation for this module Here are some examples: Data types Date = {Year, Month, Day} Time = {Hour, Minute, Second} where Year = an integer and cannot be abbreviated. E.g.: 93 denotes [...]]]></description>
			<content:encoded><![CDATA[<p>Erlang offers <strong>calendar</strong> module which provides computation of date, time and number of date time conversion functions. For more details, please refer to <a href="http://erlang.org/doc/man/calendar.html" target="_blank">documentation for this module</a><br />
Here are some examples:</p>
<h4>Data types</h4>
<p><code><br />
Date = {Year, Month, Day}<br />
Time = {Hour, Minute, Second}<br />
</code><br />
where<br />
<code><br />
Year   = an integer and cannot be abbreviated. E.g.: 93 denotes year 93, not 1993<br />
Month  = 1..12<br />
Day    = 1..31<br />
Hour   = 0..23<br />
Minute = 0..59<br />
Second = 0..59<br />
</code></p>
<h4>How to obtain local date time</h4>
<p><strong>{Date, Time} = calendar:local_time()</strong></p>
<pre class="console">
1> Current = calendar:local_time().
{{2009,9,7},{12,32,22}}
2> {{Current_Year, Current_Month, Current_Day}, _ } = Current.
{{2009,9,7},{12,32,22}}
3> Current_Year.
2009
4> Current_Month.
9
5> Current_Day.
7
6> { _, {Current_Hour, Current_Min, Current_Second}} = Current.
{{2009,9,7},{12,32,22}}
7> Current_Hour.
12
8> Current_Min.
32
9> Current_Second.
22
</pre>
<h4>How to obtain current UTC time</h4>
<p><strong>{Date, Time} = calendar:universal_time()</strong></p>
<h4>How to convert time to seconds since midnight and via versa</h4>
<p><strong>Seconds = calendar:time_to_seconds(Time)</strong><br />
<strong>Time = calendar:seconds_to_time(Seconds)</strong></p>
<pre class="console">
10> Time1 = {10, 6, 30}.
{10,6,30}
11> Seconds = calendar:time_to_seconds(Time1).
36390
12> calendar:seconds_to_time(Seconds).
{10,6,30}
</pre>
<h4>How to verify if a year is leap year</h4>
<p><strong>Bool = calendar:is_leap_year(Year)</strong></p>
<pre class="console">
14> calendar:is_leap_year(2008).
true
15> calendar:is_leap_year(2009).
false
</pre>
<h4>How to check if a date is valid</h4>
<p><strong>Bool = calendar:valid_date(Date)</strong><br />
<strong>Bool = calendar:valid_date(Year, Month, Day)</strong></p>
<pre class="console">
16> calendar:valid_date({2009,12,12}).
true
17> calendar:valid_date({2009,13,12}).
false
18> calendar:valid_date(2009, 12, 31).
true
19> calendar:valid_date(2008, 2, 29).
true
</pre>
<h4>How to find out day of the week</h4>
<p><strong>DayNumber = calendar:day_of_the_week(Date)</strong><br />
<strong>DayNumber = calendar:day_of_the_week(Year, Month, Day)</strong><br />
1 = Monday, 2 = Tuesday, &#8230;.and 7 = Sunday</p>
<pre class="console">
20> calendar:day_of_the_week({2009,9,7}).
1
21> calendar:day_of_the_week(2009, 9, 9).
3
</pre>
<h4>How to find out last day of a month</h4>
<p><strong>LastDay = calendar:last_day_of_the_month(Year, Month)</strong></p>
<pre class="console">
22> calendar:last_day_of_the_month(2008, 2).
29
23> calendar:last_day_of_the_month(2009, 8).
31
</pre>
<h4>How to calculate date time difference</h4>
<p><strong>{Days, Time} = calendar:time_difference(DT1, DT2)</strong><br />
DT1 = {Date1, Time1}<br />
DT2 = {Date2, Time2}<br />
Logically equivalent to <em>DT2 &#8211; DT1</em></p>
<pre class="console">
7> Date1={{2009,8,30}, {23,0,0}}.
{{2009,8,30},{23,0,0}}
8> Date2={{2009,9,30}, {23,0,0}}.
{{2009,9,30},{23,0,0}}
9> calendar:time_difference(Date2, Date1).
{-31,{0,0,0}}
10> calendar:time_difference(Date1, Date2).
{31,{0,0,0}}
11> Date3={{2008,8,30},{23,0,0}}.
{{2008,8,30},{23,0,0}}
12> calendar:time_difference(Date1, Date3).
{-365,{0,0,0}}
</pre>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/-26_ym1S9ok" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/09/06/date-time-manipulation-howtos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/09/06/date-time-manipulation-howtos/</feedburner:origLink></item>
		<item>
		<title>Recursion in Erlang</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/uBezcTumG98/</link>
		<comments>http://erlangexamples.com/2009/08/28/recursion-in-erlang/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 16:42:25 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[qsort]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[tail]]></category>
		<category><![CDATA[tailrecursion]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=67</guid>
		<description><![CDATA[Quick Sort I took this example from Joe Armstrong&#8217;s book: Programming Erlang to show the beauty Erlang in recursion. Classic example of quick sort implementation Can&#8217;t believe it, 6 simple and very elegant!!! I remembered roughly 10 years ago, how hard to write quick sort implementation in Pascal. Tail Recursion The quick sort implementation above [...]]]></description>
			<content:encoded><![CDATA[<h3>Quick Sort</h3>
<p>I took this example from Joe Armstrong&#8217;s book: Programming Erlang to show the beauty Erlang in recursion. Classic example of quick sort implementation</p>
<p><script src="http://gist.github.com/227835.js"></script></p>
<p>Can&#8217;t believe it, 6 simple and very elegant!!! I remembered roughly 10 years ago, how hard to write quick sort implementation in Pascal.</p>
<h3>Tail Recursion</h3>
<p>The quick sort implementation above is not tail recursive way. As the function call doesn&#8217;t return the whole results at once (look at the list concatenation). Here are few examples of tail recursion in Erlang</p>
<p><script src="http://gist.github.com/227821.js"></script></p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/uBezcTumG98" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/08/28/recursion-in-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/08/28/recursion-in-erlang/</feedburner:origLink></item>
		<item>
		<title>Diving into Emacs</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/6pGN-x1eayo/</link>
		<comments>http://erlangexamples.com/2009/08/03/diving-into-emacs/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 01:37:00 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[emacs learning curve editor ide]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/2009/08/03/diving-into-emacs/</guid>
		<description><![CDATA[I started looking at emacs as an alternative to TextMate and Eclipse for programming Erlang, especially in Windows. In fact, it&#8217;s quite hard. And I found this picture is very very true]]></description>
			<content:encoded><![CDATA[<p>I started looking at emacs as an alternative to TextMate and Eclipse for programming Erlang, especially in Windows. In fact, it&#8217;s quite hard. And I found this picture is very very true<br />
<a href="http://unix.rulez.org/~calver/pictures/curves.jpg"><img src="http://erlangexamples.com/wp-content/uploads/2009/08/editor-learning-curve.jpg" alt="editor-learning-curve" title="editor-learning-curve" width="600" height="400" class="aligncenter size-full wp-image-65" /></a></p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/6pGN-x1eayo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/08/03/diving-into-emacs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/08/03/diving-into-emacs/</feedburner:origLink></item>
		<item>
		<title>How to spawn a process</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/8lt8GhSUaJk/</link>
		<comments>http://erlangexamples.com/2009/05/15/how-to-spawn-a-process/#comments</comments>
		<pubDate>Fri, 15 May 2009 15:44:50 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[spawn]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=60</guid>
		<description><![CDATA[Erlang is all about processes and their communications. To create a process, we use BIF spawn/3 which returns the new process PID Output of the call spawn_process:do_spawn/0 is the Pid of the newly created process. ?MODULE is the macro refers to the current module 1&#62; spawn_process:do_spawn(). "hello" "process" &#60;0.33.0&#62; 2&#62;]]></description>
			<content:encoded><![CDATA[<p>Erlang is all about processes and their communications. To create a process, we use BIF <strong>spawn/3</strong> which returns the new process PID</p>
<pre class="brush: erlang; title: ; notranslate">
-module(spawn_process).
-export([do_spawn/0, call/2]).

call(Arg1, Arg2) -&gt;
    io:format(&quot;~p ~p~n&quot;, [Arg1, Arg2]).

do_spawn() -&gt;
    %% Equivalent to SpawnProcess:call(&quot;hello&quot;, &quot;process&quot;),
    Pid = spawn(?MODULE, call, [&quot;hello&quot;, &quot;process&quot;]),
    Pid.
</pre>
<p>Output of the call <strong>spawn_process:do_spawn/0</strong> is the Pid of the newly created process. <strong><span style="text-decoration: underline;">?MODULE</span></strong> is the macro refers to the current module</p>
<pre class="console">1&gt; spawn_process:do_spawn().
"hello" "process"
&lt;0.33.0&gt;
2&gt;</pre>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/8lt8GhSUaJk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/05/15/how-to-spawn-a-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/05/15/how-to-spawn-a-process/</feedburner:origLink></item>
		<item>
		<title>How to create and manipulate records</title>
		<link>http://feedproxy.google.com/~r/ErlangExamples/~3/AlQiYUaSQrQ/</link>
		<comments>http://erlangexamples.com/2009/03/09/how-to-create-and-manipulate-records/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 09:23:58 +0000</pubDate>
		<dc:creator>Trung</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[hrl]]></category>
		<category><![CDATA[records]]></category>

		<guid isPermaLink="false">http://erlangexamples.com/?p=50</guid>
		<description><![CDATA[As I remember the first time I was tought about Object-Oriented paradigm, my teacher told me &#8220;everything around you is an object&#8221; &#8230; Damn, since then I couldn&#8217;t get rid of that even when programming with Erlang. People say Records concept in Erlang is very similar to struct in C. That&#8217;s true, but for me, [...]]]></description>
			<content:encoded><![CDATA[<p>As I remember the first time I was tought about Object-Oriented paradigm, my teacher told me &#8220;everything around you is an object&#8221; &#8230; Damn, since then I couldn&#8217;t get rid of that even when programming with Erlang.</p>
<p>People say <strong>Records</strong> concept in Erlang is very similar to <strong>struct</strong> in C. That&#8217;s true, but for me, it looks rather like an <strong>Object</strong>&#8230;</p>
<p>Normally, records are defined in a separate file with extension <strong>.hrl</strong> and included in the main module file.</p>
<p><span style="text-decoration: underline;"><strong>person.hrl</strong></span></p>
<pre class="brush: erlang; title: ; notranslate">
%% person.hrl
-record(person, {name, age}).
</pre>
<p>Here I define a record, named <strong>person</strong>, which has 2 attributes <strong>name</strong> and <strong>age</strong>. I&#8217;ll use erl console to do some manipulation with record <strong>person</strong></p>
<pre class="console">1&gt; rr("person.hrl").
[person]
2&gt; X = #person{name="Jonny", age="18"}.
#person{name = "Jonny",age = "18"}
3&gt; X#person.name.
"Jonny"
4&gt; X#person.age.
"18"
5&gt; #person{name=Name} = X.
#person{name = "Jonny",age = "18"}
6&gt; Name.
"Jonny"</pre>
<p>1&gt; I <span style="text-decoration: underline;"><strong>r</strong></span>ead <span style="text-decoration: underline;"><strong>r</strong></span>ecord <strong>person</strong> defined in <strong>person.hrl</strong><br />
2&gt; I created a new &#8220;object&#8221; of type <strong>person</strong> and assigned to variable <em>X</em><br />
3&gt; I printed value of the attribute <strong>name</strong> from &#8220;object&#8221; <em>X</em><br />
4&gt; I printed value of the attribute <strong>age</strong> from &#8220;object&#8221; <em>X</em><br />
5&gt; I used pattern matching to extract value of the attribute <strong>name</strong> out of &#8220;object&#8221; <em>X</em> and assigned to variable <strong>Name</strong><br />
6&gt; I printed value of variable <strong>Name</strong></p>
<img src="http://feeds.feedburner.com/~r/ErlangExamples/~4/AlQiYUaSQrQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://erlangexamples.com/2009/03/09/how-to-create-and-manipulate-records/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://erlangexamples.com/2009/03/09/how-to-create-and-manipulate-records/</feedburner:origLink></item>
	</channel>
</rss>
