<?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>Bosque Viejo</title>
	<atom:link href="http://bosqueviejo.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://bosqueviejo.net</link>
	<description>Blog sobre programación, software libre, redes, servidores, ...</description>
	<lastBuildDate>Thu, 16 May 2013 22:58:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>The black list</title>
		<link>http://bosqueviejo.net/en/2012/12/13/blacklist/</link>
		<comments>http://bosqueviejo.net/en/2012/12/13/blacklist/#comments</comments>
		<pubDate>Thu, 13 Dec 2012 11:17:02 +0000</pubDate>
		<dc:creator>bombadil</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[blacklist]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://bosqueviejo.net/?p=1634</guid>
		<description><![CDATA[While I keep fail2ban active in my server and with high restrictions, I&#8217;m starting to put the usual suspects in a permanent blacklist. This IP adresses belongs to companies or people who are difficult to contact and/or haven&#8217;t an abuse email address to inform them about unethical actions as brute force attacks via SSH. In my specific case, in Spain,&#8230;]]></description>
				<content:encoded><![CDATA[<p><img src="http://bosqueviejo.net/wp-content/uploads/Hacker-and-Cracker-150x150.jpg" alt="Hacker in the front of a laptop computer" width="150" height="150" class="alignleft size-thumbnail wp-image-1635" /> While I keep <a href="http://www.fail2ban.org/wiki/index.php/Main_Page">fail2ban</a> active in my server and with high restrictions, I&#8217;m starting to put the usual suspects in a permanent blacklist. This IP adresses belongs to companies or people who are difficult to contact and/or haven&#8217;t an <emphasis>abuse</emphasis> email address to inform them about unethical actions as brute force attacks via SSH.</p>
<p>In my specific case, in Spain, for people that has their own servers and serve their own content as this blog to users in spanish language (mainly) this IP adresses could be lock by default. This IP adress are from servers with contents in another languages as russian or chinesse. Therefore, I did make my small contribution to the comunity with this file, to avoid the attacks from this IP adress in other servers:</p>
<p><a href="http://bosqueviejo.net/wp-content/uploads/blacklist">The list</a></p>
<p>If someone found in this list any IP that shouldn&#8217;t appears in, only add a comment to study its exclusion from the list.</p>
<p>The installation could be automated in GNU/Linux systems as script at system boot in the following way:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="shell" style="font-family:monospace;">curl http://bosqueviejo.net/wp-content/uploads/blacklist | sh</pre></td></tr></table></div>

<p>Always run it as <emphasis>root</emphasis> user.</p>
]]></content:encoded>
			<wfw:commentRss>http://bosqueviejo.net/en/2012/12/13/blacklist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang shell history</title>
		<link>http://bosqueviejo.net/en/2012/11/28/erlang-shell-con-historia/</link>
		<comments>http://bosqueviejo.net/en/2012/11/28/erlang-shell-con-historia/#comments</comments>
		<pubDate>Wed, 28 Nov 2012 17:56:02 +0000</pubDate>
		<dc:creator>bombadil</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[ferd]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[learn you some erlang]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://bosqueviejo.net/?p=1620</guid>
		<description><![CDATA[One feature available in bash or zsh shells is the history. When the shell is closed and opened again, we can show the history for find statements or commands we typed for minutes or days ago. Thanks to Ferd aportation (author of Learn You Some Erlang), we have history in Erlang shell too. Throught the project erlang-history, with an easy&#8230;]]></description>
				<content:encoded><![CDATA[<p><img src="http://bosqueviejo.net/wp-content/uploads/ferd-150x150.png" alt="" title="ferd" width="150" height="150" class="alignleft size-thumbnail wp-image-1621" /> One feature available in <a href="http://www.gnu.org/software/bash/">bash</a> or <a href="http://en.wikipedia.org/wiki/Z_shell">zsh</a> shells is the history. When the shell is closed and opened again, we can show the history for find statements or commands we typed for minutes or days ago.</p>
<p>Thanks to <a href="http://ferd.ca/">Ferd</a> aportation (author of <a href="http://learnyousomeerlang.com/">Learn You Some Erlang</a>), we have history in Erlang shell too. Throught the project <a href="https://github.com/ferd/erlang-history">erlang-history</a>, with an easy installation we can use the history with the Erlang shell.</p>
<p>A fast way to do it:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="shell" style="font-family:monospace;">git clone git://github.com/ferd/erlang-history.git
cd erlang-history
make install</pre></td></tr></table></div>

<p>You can see the configuration in the project&#8217;s official website: <a href="https://github.com/ferd/erlang-history">erlang-history</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bosqueviejo.net/en/2012/11/28/erlang-shell-con-historia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ErlDev 0.2 released</title>
		<link>http://bosqueviejo.net/en/2012/06/08/erldev-0-2-liberada/</link>
		<comments>http://bosqueviejo.net/en/2012/06/08/erldev-0-2-liberada/#comments</comments>
		<pubDate>Fri, 08 Jun 2012 05:50:43 +0000</pubDate>
		<dc:creator>bombadil</dc:creator>
				<category><![CDATA[Noticias]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[erldev]]></category>
		<category><![CDATA[rebar]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://bosqueviejo.net/?p=1415</guid>
		<description><![CDATA[Has been released Erldev 0.2 version. This new version give up enhancements to coding in Erlang environments: new templates, more packages, etc. It has a new syntax for projects, we have dropped the original simple/multi structure and now, has only one simple model. In this way, an application could be created and has in contrib dir another projects as dependencies.&#8230;]]></description>
				<content:encoded><![CDATA[<p><img src="http://bosqueviejo.net/wp-content/uploads/coding-150x150.jpg" alt="" title="coding" width="150" height="150" class="alignleft size-thumbnail wp-image-1416" /> Has been released Erldev 0.2 version. This new version give up enhancements to coding in Erlang environments: new templates, more packages, etc.</p>
<p>It has a <strong>new syntax for projects</strong>, we have dropped the original simple/multi structure and now, has only one simple model. In this way, an application could be created and has in contrib dir another projects as dependencies. However, the configure execution in dependencies is a task to do.</p>
<p>Added <strong>start-dev.sh script</strong>, which let us run the code without install the application. This is a standard in a lot of other projects in Internet. However we can uso too the <tt>make run</tt> format to do this.</p>
<p>Added <strong>rebar</strong> use insted of Makefile. Although rebar is a tool very similar to erldev, erldev is oriented to use GNU buildtools, as many projects in serveral languages in Internet. Among, rebar dependencies is based in download from original repositories as github and, Erldev is as Debian repositories, is based in use its own repositories to mantains the versions and code to build your application without worry if these code is there or not.</p>
<p>All you need you can find it at: <a href="http://erldev.org">http://erldev.org</a></p>
<p>New packages added or upgraded: cowboy, proper, dispcount, gen_leader, lager, quoted y tls.</p>
<p>Any comment you could write a comment below or go to user forum at ErlDev site.</p>
]]></content:encoded>
			<wfw:commentRss>http://bosqueviejo.net/en/2012/06/08/erldev-0-2-liberada/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Las gemas de Ruby</title>
		<link>http://bosqueviejo.net/en/2012/01/02/las-gemas-de-ruby/</link>
		<comments>http://bosqueviejo.net/en/2012/01/02/las-gemas-de-ruby/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 17:03:31 +0000</pubDate>
		<dc:creator>bombadil</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://bosqueviejo.net/?p=1165</guid>
		<description><![CDATA[Tengo a Ruby un poco abandonado, por lo que me he decidido a escribir un poco acerca de él, al igual que hice con Python, para detallar un poco cómo son los paquetes de código (o librerías) de Ruby: las gemas. Las gemas de Ruby son paquetes de librerías para Ruby que se instalan en el sistema y quedan listas&#8230;]]></description>
				<content:encoded><![CDATA[<p><img src="http://bosqueviejo.net/wp-content/uploads/rubygems-150x150.jpg" alt="" title="rubygems" width="150" height="150" class="alignleft size-thumbnail wp-image-1166" /> Tengo a Ruby un poco abandonado, por lo que me he decidido a escribir un poco acerca de él, al igual que hice con Python, para detallar un poco cómo son los paquetes de código (o librerías) de Ruby: las gemas.<span id="more-1165"></span></p>
<p>Las gemas de Ruby son paquetes de librerías para Ruby que se instalan en el sistema y quedan listas para ser usadas, con un simple <em>require</em> o con mecanismos que aporta el propio sistema de gemas para Ruby.</p>
<h3>El gestor de gemas: rubygems</h3>
<p>En distribuciones de GNU/Linux, e instalaciones automáticas para Windows, se nos habilita un comando, generalmente, que nos permite agregar librerías y código de un repositorio muy extenso de código listo para usar. Esto es conocido como el gestor de gemas, <em>rubygems</em>, o simplemente <em>gem</em>.</p>
<p>El gestor de gemas es un comando que nos permite listar las gemas instaladas, buscar gemas remotas o localmente (de las instaladas), instalar, actualizar y eliminar gemas. Se puede saber si está instalado simplemente ejecutando:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="shell" style="font-family:monospace;">gem --version</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bosqueviejo.net/en/2012/01/02/las-gemas-de-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang, do they really understand?</title>
		<link>http://bosqueviejo.net/en/2011/08/11/erlang-realmente-lo-entienden/</link>
		<comments>http://bosqueviejo.net/en/2011/08/11/erlang-realmente-lo-entienden/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 15:17:50 +0000</pubDate>
		<dc:creator>bombadil</dc:creator>
				<category><![CDATA[Opinión]]></category>
		<category><![CDATA[desarrollo software]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programación concurrente]]></category>

		<guid isPermaLink="false">http://bosqueviejo.net/?p=826</guid>
		<description><![CDATA[After reading several posts about Erlang, some posts defending it and others criticizing it, I thought, really, not all people really understand it. The important thing is, the methodology behind the language. Criticizing its style Is curious that people as Damien Katz (founder of CouchDB), or Toni Arcieri (founder of Reia) has been the first persons criticizing the language they&#8230;]]></description>
				<content:encoded><![CDATA[<p><img src="http://bosqueviejo.net/wp-content/uploads/criticar_discernir_2-150x150.png" alt="" title="criticar_discernir_2" width="150" height="150" class="alignleft size-thumbnail wp-image-828" /> After reading several posts about Erlang, some posts defending it and others criticizing it, I thought, really, not all people really understand it. The important thing is, the methodology behind the language.</p>
<h3>Criticizing its style</h3>
<p>Is curious that people as <a href="http://damienkatz.net/">Damien Katz</a> (founder of <a href="http://couchdb.apache.org/">CouchDB</a>), or <a href="http://www.unlimitednovelty.com/">Toni Arcieri</a> (founder of <a href="http://reia-lang.org/">Reia</a>) has been the first persons criticizing the language they choose to write their software for.</p>
<p>In this sense, others as <a href="http://yarivsblog.blogspot.com/">Yariv Sadan</a>, have defended and recognized some comments and, before read both, I asked myself&#8230; <strong>have they really understand what Erlang is?, what it does and what are it&#8217;s powers?, how to make the most of it, as well as concurrency oriented programming?</strong></p>
<h3>Criticizing the sintaxis</h3>
<p>First, all people criticize Erlang for is its syntax. I remember the first time i saw C language. I was programming in Basic, Pascal and Modula-2 and i said&#8230; how bizarre! and the same when i saw Perl some years later <img src='http://bosqueviejo.net/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<p>The C-like syntax is very used in programming world, but is not understandable for a person that start from scratch to program. Niklaus Wirth develop some languages as Pascal, to teach to program in pseudocode way.</p>
<p>Erlang, however, follows a methodology such as Prolog, is oriented to the development of mathematical functions, so then function has a closure (->) for its begin and ends with a dot. Each element inside of mathematical function or expression is separated by commas, and all is functional, ergo, all element in Erlang do something and MUST returns something, even the condicional structures, therefore has the way it has.</p>
<h3>Data types: records and strings</h3>
<p>The records are, at preprocessor level: tuples. This is that, functions as <em>record_info</em> does not really exists, therefore do not use variables in this macro and the records has a limitation. However, there are some tricks to use to do it in this way.</p>
<p>Another problem, with data types, are strings. The strings are integer lists. This not should surprise, in all languages are byte lists (or arrays). In C language, by example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> c<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;This is a string&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">char</span> d<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">'T'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'h'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'i'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'s'</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">32</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'i'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'s'</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">32</span><span style="color: #339933;">,</span> ...<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066;">strcmp</span><span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span> d<span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000dd;">0</span> <span style="color: #339933;">?</span> <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This give us true, because both byte lists are equals. In Erlang can see something like this with integer lists:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #109ab8;">&#91;</span><span style="color: #ff9600;">100</span><span style="color: #6bb810;">,</span><span style="color: #ff9600;">111</span><span style="color: #6bb810;">,</span><span style="color: #ff9600;">103</span><span style="color: #109ab8;">&#93;</span> <span style="color: #014ea4;">==</span> <span style="color: #ff7800;">&quot;dog&quot;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>This returns true too.</p>
<h3>Performance</h3>
<p>Really, after reading the <a href="http://www.unlimitednovelty.com/2011/07/trouble-with-erlang-or-erlang-is-ghetto.html">Toni</a> post, when I read: <em>Erlang sucks at managing memory</em>; he talks about a Erlang and <a href="http://www.azulsystems.com/products/vega/processor">Azul Vega</a> comparation. Azul Vega is a 54-core processor optimized to run a JVM special.</p>
<p>A software with these processor and these JVM, NOT run in a distributed fashion, really, only will be distributed tasks between internal cores. Therefore, the procesor is not designed to connect to another nodes, therefore NOT is scalable. Also, only has four channels to memory access. In a 27 nodes cluster of Pentium IV with HyperThreading, we can do this work using Erlang&#8230; and also we can scale to more nodes.</p>
<h3>Is a general porpouse language?</h3>
<p>Erlang was created for environments to develop concurrent software, this feature is ideal for all kind servers, and now, for modern desktops, where software should run in a concurrent way.</p>
<p>Can Erlang develop web applications?, Yes, ChicagoBoss, or Erlyweb, or Nitrogen are examples for this. Can Erlang develop desktop applications? Yes, Wings3D is a good example for this. Does Erlang use to do server applications? Sure! was created for this.</p>
<p>In my opinion, if PHP has this denomination and is a markup language, Erlang MUST has it <img src='http://bosqueviejo.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<h3>Unique assigment&#8230; why?</h3>
<p>To trace better the code, sure, and because a functional language do not need too many variables. By example, as say Damien Katz en his post, has this code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">f</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
  <span style="color: #45b3e6;">X1</span> <span style="color: #014ea4;">=</span> <span style="color: #ff3c00;">foo</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
  <span style="color: #45b3e6;">X2</span> <span style="color: #014ea4;">=</span> <span style="color: #ff3c00;">bar</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X1</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
  <span style="color: #ff3c00;">baz</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X2</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>This code, well write:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">f</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
  <span style="color: #ff3c00;">baz</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">bar</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">foo</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>Do you like add logs to see the change between function calls? &#8230; then you can do with another functions:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">log</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Caller</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;~s: ~p~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">Caller</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">X</span><span style="color: #6bb810;">.</span>
<span style="color: #ff3c00;">f</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
  <span style="color: #ff3c00;">log</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;BAZ: &quot;</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">baz</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">log</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;BAR: &quot;</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">bar</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">log</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;FOO: &quot;</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">foo</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">X</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>Is not really complex wheter you write and sort the code in a correct way&#8230; in other languages, as in example C, we can write code as this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>s <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Count this string&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> size<span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> size<span style="color: #339933;">;</span> s<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span> <span style="color: #339933;">&amp;&amp;</span> i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">100</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++,</span> size<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Another codes in Perl are more afraid&#8230; but it always depends of the programmer.</p>
<h3>The development itself</h3>
<p>I think that is not understable, is the development in Erlang, as is, is not scalable, nor redundant, nor leverage all cores and machine processors, so as the rest of connecting nodes. To take avantage of Erlang is develop software in a concurrent fashion, with the correct patterns.</p>
<p>By example, Erlang can run, only in a node, almost 2 millions of concurrent process. This is, each task to do should run in its own process, and this process launched in appropiate core, processor and/or node. As well as we develop software wich PVM or MPICH.</p>
<p>Use OTP patterns is essential to take the maximum avantage of Erlang architecture and to create event handlers, state machines, shared memories in several servers, etc. should do, necessary, throught the Erlang mechanisms.</p>
<p>If we use Erlang to do calls to Mnesia, from any part of code with the <em>dirty</em> calls and generating a new process for each isolated request, we have a software with concurrent potential errors and, that no take avantage of configurated and connected nodes in the system.</p>
<h3>Ending</h3>
<p>I feel unprofesional write this kind of posts, both Tony and Damien, where write a list of circunstances slightly contrasted and due to low knowledge of language and, precisely they, they has been developed great applications in this language.</p>
<p>Java, seamsly, is a great language, but as Tony comment in his post, require of RTSJ specification in the JVM, in the comparisons, by example, even talks about buy special hardware to develop something like Erlang does in every architecture, i think they are less objetives.</p>
]]></content:encoded>
			<wfw:commentRss>http://bosqueviejo.net/en/2011/08/11/erlang-realmente-lo-entienden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FSM: Máquina de Estados en Erlang</title>
		<link>http://bosqueviejo.net/en/2011/08/03/fsm-maquina-de-estados-en-erlang/</link>
		<comments>http://bosqueviejo.net/en/2011/08/03/fsm-maquina-de-estados-en-erlang/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 11:40:30 +0000</pubDate>
		<dc:creator>bombadil</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[gen_fsm]]></category>
		<category><![CDATA[otp]]></category>
		<category><![CDATA[programación concurrente]]></category>

		<guid isPermaLink="false">http://bosqueviejo.net/?p=810</guid>
		<description><![CDATA[FSM or Finite State Machine, is one of powerful tool that OTP give us to develop applications and solutions. The finite state machines can be used to define elements to interacts with an application. Begins in a defined state and throught events, can change its state until its ending. A finite state machine can be somthing simpler as an alarm&#8230;]]></description>
				<content:encoded><![CDATA[<p><img src="http://bosqueviejo.net/wp-content/uploads/erlang-150x150.jpg" alt="" title="erlang" width="150" height="150" class="alignleft size-thumbnail wp-image-822" /> FSM or Finite State Machine, is one of powerful tool that OTP give us to develop applications and solutions.</p>
<p>The finite state machines can be used to define elements to interacts with an application. Begins in a defined state and throught events, can change its state until its ending.</p>
<p>A finite state machine can be somthing simpler as an alarm clock (or cron system), or a bank transaction, or a phone call, &#8230;</p>
<p>In this post I develop an example to show you the simple to develop this problems using OTP.</p>
<h3>The Finite State Machine Generator</h3>
<p>In the Erlang OTP set of functions, has one specific that is named <em>gen_fsm</em>. This is the short name to <em>generator: finite state machine</em>. As his name say, is a generator. The generators, in Eralng/OTP are behaviours, base code used as framework to develop a specific behaviour.</p>
<p>A module in Erlang is as simpler as define the first line with the module name, specify the functions export and, after that define the functions. The smallest module that you can write could has three lines of code.</p>
<p>The generators are different, these need a specific line to indicate the behaviour to implement and the definition of all <em>callbacks</em> for the base code.</p>
<p>Itself, the <em>gen_fsm</em> is the base code that keeps running and, when an event arrive, this code generate a call to a specific function (a callback). By convention, the <em>callbacks</em> has a specific form, both in name and in params, and the returns is normalized as well.</p>
<p>To make things easier, we rely on <a href="http://erldev.org/browser/trunk/templates/gen_fsm.erl">this template</a>, but suppressing comments to not take up much.</p>
<h3>Elevator example</h3>
<p>This examples is very simple. Supose that we have an elevator to three floors: ground, first and second. This elevator has only two buttons labeled as: up and down; stops in every floor each time. Therefore, depending on the floor that is, the buttons has valid functionality or not.</p>
<p><img src="http://bosqueviejo.net/wp-content/uploads/ascensor_simple-300x150.png" alt="" title="ascensor_simple" width="300" height="150" class="aligncenter size-medium wp-image-816" /></p>
<p>If we are inside of elevator, in the first floor, we can press up button or down button, the elevator will have an state to go&#8230; but if we are in the ground floor (B), by example, press the down button has no sense.</p>
<h3>Developing the solution</h3>
<p>The code, giving the <em>gen_fsm</em> template will be simple. We have three states and two events by state. We have six functions to develop:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #014ea4;">-</span><span style="color: #5400b3;">module</span><span style="color: #109ab8;">&#40;</span>elevator<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
<span style="color: #014ea4;">-</span><span style="color: #5400b3;">behaviour</span><span style="color: #109ab8;">&#40;</span>gen_fsm<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #014ea4;">-</span><span style="color: #5400b3;">compile</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span>export_all<span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span> <span style="color: #666666; font-style: italic;">% to do: change by -export(...).</span>
&nbsp;
<span style="color: #014ea4;">-</span><span style="color: #5400b3;">record</span><span style="color: #109ab8;">&#40;</span><span style="color: #d400ed;">state</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">start_link</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">gen_fsm</span>:<span style="color: #ff3c00;">start_link</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#123;</span>local<span style="color: #6bb810;">,</span> ?<span style="color: #6941fd;">MODULE</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">,</span> ?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">init</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#123;</span>ok<span style="color: #6bb810;">,</span> ground_floor<span style="color: #6bb810;">,</span> #<span style="color: #d400ed;">state</span><span style="color: #109ab8;">&#123;</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">ground_floor</span><span style="color: #109ab8;">&#40;</span>down<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Beeep!, invalid option~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> ground_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">ground_floor</span><span style="color: #109ab8;">&#40;</span>up<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Up to first floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> first_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">first_floor</span><span style="color: #109ab8;">&#40;</span>down<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Down to ground floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> ground_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">first_floor</span><span style="color: #109ab8;">&#40;</span>up<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Up to second floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> second_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">second_floor</span><span style="color: #109ab8;">&#40;</span>down<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Down to first floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> first floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">second_floor</span><span style="color: #109ab8;">&#40;</span>up<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Beeep!, invalid option~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> second_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% add two functions to make calls easy</span>
<span style="color: #666666; font-style: italic;">% they are optional:</span>
&nbsp;
<span style="color: #ff3c00;">up_button</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">gen_fsm</span>:<span style="color: #ff3c00;">send_event</span><span style="color: #109ab8;">&#40;</span>?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> up<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">down_button</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">gen_fsm</span>:<span style="color: #ff3c00;">send_event</span><span style="color: #109ab8;">&#40;</span>?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> down<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>If you see the figure, and the code convertion, you will see that there are a direct relation between the schema  and the code. This make develop very easy a state system as: bank transaction, internet payment, bidding, a phone call, a contest, a videogame, etc.</p>
<h3>How works</h3>
<p>The function <em>start_link</em>, and which are defined below, they are not really of the system itself, but helpers to run the state machine and interact with it.</p>
<p>The state machine, at the begining run <em>init</em> function. This function give an state and let pass data to keep between calls or events to FSM.</p>
<p>Once are running, the base code call the appropiate function, named as current state name.</p>
<h3>Running the code</h3>
<p>Once the write the code, we can run the Erlang virtual machine and run without problems:</p>
<pre>
$ erl
[...]
1> c(elevator). % compile the code.
{ok,elevator}
2> elevator:start_link(). % launch the state machine.
{ok,<0.38.0>}
3> elevator:down_button().
Beeep!, invalid option
ok
4> elevator:up_button().
Up to first floor
ok
</pre>
<p>The state machine does the calls to the functions, according to the state it is and the event que was launch.</p>
<h3>Adding time</h3>
<p>A good thing about FSM, is that, not only has events by calls, but also by time, therefore, in the example, we can add that, the elevator does not keep in the same floor more than 5 seconds, going up and down each time, until press a button.</p>
<p>Here we need the memory to know, if we going from up, then goes to down, when arrive to first floor, and vice versa.</p>
<p>Adding memory is as simpler as modify the state record to indicate the address to go:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #014ea4;">-</span><span style="color: #5400b3;">record</span><span style="color: #109ab8;">&#40;</span><span style="color: #d400ed;">state</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>address<span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">init</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#123;</span>ok<span style="color: #6bb810;">,</span> ground_floor<span style="color: #6bb810;">,</span> #<span style="color: #d400ed;">state</span><span style="color: #109ab8;">&#123;</span>address<span style="color: #014ea4;">=</span>up<span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>The time is measured in miliseconds, therefore this code does the elevator start and, if not press a button in 5 seconds, the elevator goes up alone. In this case we add a new event:</p>
<p><img src="http://bosqueviejo.net/wp-content/uploads/ascensor_timeout-300x150.png" alt="" title="ascensor_timeout" width="300" height="150" class="aligncenter size-medium wp-image-820" /></p>
<p>The new functions:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">ground_floor</span><span style="color: #109ab8;">&#40;</span>down<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">_State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Beeep!, incorrect option~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> ground_floor<span style="color: #6bb810;">,</span> #<span style="color: #d400ed;">state</span><span style="color: #109ab8;">&#123;</span>address<span style="color: #014ea4;">=</span>up<span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">ground_floor</span><span style="color: #109ab8;">&#40;</span>up<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">_State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Up to first floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> first_floor<span style="color: #6bb810;">,</span> #<span style="color: #d400ed;">state</span><span style="color: #109ab8;">&#123;</span>address<span style="color: #014ea4;">=</span>up<span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">ground_floor</span><span style="color: #109ab8;">&#40;</span><span style="color: #fa6fff;">time</span>out<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">_State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Up automatic to first floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> first_floor<span style="color: #6bb810;">,</span> #<span style="color: #d400ed;">state</span><span style="color: #109ab8;">&#123;</span>address<span style="color: #014ea4;">=</span>up<span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">first_floor</span><span style="color: #109ab8;">&#40;</span>down<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Down to ground floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> ground_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">first_floor</span><span style="color: #109ab8;">&#40;</span>up<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Up to second floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> second_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">first_floor</span><span style="color: #109ab8;">&#40;</span><span style="color: #fa6fff;">time</span>out<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #45b3e6;">NextState</span> <span style="color: #014ea4;">=</span> <span style="color: #186895;">case</span> <span style="color: #45b3e6;">State</span><span style="color: #ff9600;">#</span><span style="color: #d400ed;">state</span><span style="color: #6bb810;">.</span>address <span style="color: #186895;">of</span>
        up <span style="color: #6bb810;">-&gt;</span> 
            <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Up automatic to second floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
            second_floor<span style="color: #6bb810;">;</span>
        down <span style="color: #6bb810;">-&gt;</span>
            <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Down automatic to ground floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
            ground_floor
    <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">NextState</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">second_floor</span><span style="color: #109ab8;">&#40;</span>down<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Down to first floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> first_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">second_floor</span><span style="color: #109ab8;">&#40;</span>up<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Beeep!, incorrect option~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> second_floor<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">second_floor</span><span style="color: #109ab8;">&#40;</span><span style="color: #fa6fff;">time</span>out<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">_State</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">io</span>:<span style="color: #ff3c00;">format</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;Down automatic to first floor~n&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #109ab8;">&#123;</span>next_state<span style="color: #6bb810;">,</span> first_floor<span style="color: #6bb810;">,</span> #<span style="color: #d400ed;">state</span><span style="color: #109ab8;">&#123;</span>address<span style="color: #014ea4;">=</span>down<span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">5000</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<p>With this, we have the three states, with the three events, ergo, the code for the nine possible functions that can be in runtime.</p>
<p>In case of have a lot of states, we could use the <em>handle_event</em> format, the state name will be the first param and could admin throught code. The events works so, therefore in this sense, can be unify or optimize.</p>
<h3>Ending</h3>
<p>The FSM systems for Erlang, give us a big power to do, in easy fashion, an element that, in case of will be asked or generating evetns from several concurrent places, its interface does its behaviour will be the appropiate in each moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://bosqueviejo.net/en/2011/08/03/fsm-maquina-de-estados-en-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
