<?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>Virtual Clouds &#187; erlang</title>
	<atom:link href="http://www.virtual-clouds.com/tag/erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.virtual-clouds.com</link>
	<description>Erlang and Other Animals</description>
	<lastBuildDate>Mon, 19 Jul 2010 17:42:56 +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>nitrogen</title>
		<link>http://www.virtual-clouds.com/2009/01/51/nitrogen/</link>
		<comments>http://www.virtual-clouds.com/2009/01/51/nitrogen/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 23:32:30 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[tools]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=51</guid>
		<description><![CDATA[i have stumbled upon a very promissing web framwork for erlang. nitrogen, altough very young (first release was around December 2008), it seems exactly what i have looking for. it actually bring the erlang into the web, allowing to develope a true erlang based web app. nitrogen have several appealing features. the framwork support ajax/comet, <a href='http://www.virtual-clouds.com/2009/01/51/nitrogen/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>i have stumbled upon a very promissing web framwork for erlang. <a href="http://nitrogenproject.com/">nitrogen</a>, altough very young (first release was around December 2008), it seems exactly what i have looking for. it actually bring the erlang into the web, allowing to develope a true erlang based web app.</p>
<p>nitrogen have several appealing features. the framwork support ajax/comet, which is absolutely a shame how easy it ease to use. it allows defining html templates, with &#8216;holes&#8217; in it to insert content from the erlang source. but the real benefit is the ability to write those &#8216;holes&#8217; in erlang modules. those &#8216;holes&#8217; are filled with elements which are parallel to html structures, and because you are using erlang sytax to describe them, you can use the erlang pattern matching and messaging system in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2009/01/51/nitrogen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>colinux strikes back</title>
		<link>http://www.virtual-clouds.com/2009/01/49/colinux-strikes-back/</link>
		<comments>http://www.virtual-clouds.com/2009/01/49/colinux-strikes-back/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 23:30:38 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[tools]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=49</guid>
		<description><![CDATA[because the colinux images are very old, i have decided to build one of my own, based on ubuntu 8.10. so, i followed this post, to create my colinux image. keep in mind installing ubuntu using qemu on windows takes ages (really, few hours, so schedule it to an hour before you go to sleep). <a href='http://www.virtual-clouds.com/2009/01/49/colinux-strikes-back/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>because the colinux images are very old, i have decided to build one of my own, based on ubuntu 8.10. so, i followed this <a href="http://colinux.wikia.com/wiki/Ubuntu61">post</a>, to create my colinux image. keep in mind installing ubuntu using qemu on windows takes ages (really, few hours, so schedule it to an hour before you go to sleep).</p>
<p>later, i just added another conf file to start this colinux, see more details on me previous post:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">kernel=vmlinux
sda1=&quot;c:\linux\distro\ubuntu_8.10.ext3.3gb.img&quot;
sda2=&quot;c:\linux\distro\ext3_disk_1gb.img&quot;
sdb1=&quot;c:\linux\distro\swap_512mb&quot;
root=/dev/sda1 fastboot 3
ro
mem=384
eth0=slirp
eth1=tuntap</pre></div></div>

<p>moreover, i edited the network and samba, again, as i posted before. afterward i have installed erlang and yaws. finally, few fixes and tweaks i have encountered.</p>
<p>because i want it as a server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> linux-headers-server linux-image-server linux-server</pre></div></div>

<p>to solve and odd error message on startup (mmap: Bad address):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove dmidecode <span style="color: #660033;">--purge</span></pre></div></div>

<p>to prevent yaws, and few other services i don&#8217;t need to start after boot:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d <span style="color: #660033;">-f</span> bluetooth remove
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d <span style="color: #660033;">-f</span> gdm remove
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d <span style="color: #660033;">-f</span> yaws remove</pre></div></div>

<p>that&#8217;s it! if you got so far, you are now officialy an uber-geek <img src='http://www.virtual-clouds.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2009/01/49/colinux-strikes-back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>code coverage in erlang</title>
		<link>http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/</link>
		<comments>http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 22:15:17 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=24</guid>
		<description><![CDATA[yesterday i found about code coverage under erlang on this nice blog. i wanted to integrate it with my unit testing, so i would be able to see what code of mine is not tested. this can be used to add new tests to cover it, or even remove of unnecessary code. it took me <a href='http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>yesterday i found about code coverage under erlang on this nice <a href="http://curious-attempt-bunny.blogspot.com/2007/10/code-coverage-analysis-in-erlang.html">blog</a>. i wanted to integrate it with my unit testing, so i would be able to see what code of mine is not tested. this can be used to add new tests to cover it, or even remove of unnecessary code.</p>
<p>it took me some time to play with it and come up with a good method of doing that. eventually i have replaced the unit testing makefile line with:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">check<span style="color: #004400;">:</span>
	<span style="color: #004400;">@</span>for f in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do \
	echo <span style="color: #000088; font-weight: bold;">$$</span>f<span style="color: #004400;">;</span> \
	erl <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">FLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>noshell <span style="color: #004400;">-</span>eval <span style="color: #CC2200;">&quot;
	cover:compile($$f, [{i,<span style="color: #000099; font-weight: bold;">\&quot;</span>$(INCLUDE)<span style="color: #000099; font-weight: bold;">\&quot;</span>}]),<span style="color: #000099; font-weight: bold;">\</span>
	$$f:test(),
	cover:analyse_to_file($$f, <span style="color: #000099; font-weight: bold;">\&quot;</span>$(DOC)/$${f}_coverage.html<span style="color: #000099; font-weight: bold;">\&quot;</span>, [html]).&quot;</span>\
	<span style="color: #004400;">-</span>s init stop<span style="color: #004400;">;</span> \</pre></div></div>

<p>This actually do 3 things in a raw:</p>
<ol>
<li>compile each module using cover:compile.</li>
<li>run the test, using the eunit test() function.</li>
<li>dump analysis into html files on doc directory</li>
</ol>
<p>enjoy!</p>
<p>edit: i found out, that you compile the whole directory for covearge, so the result you get is thecombined  coverage for all the specified modules and tests.</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">OBJECTS <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BIN</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/%.$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">EMULATOR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
MODULES <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,%,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
SKIP_FILES <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,%,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*</span>_tests<span style="color: #004400;">.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
MODULES <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">filter-out</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SKIP_FILES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
MODULES <span style="color: #004400;">:=</span> <span style="color: #004400;">&#91;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">subst</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">space</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">comma</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#93;</span>
&nbsp;
check<span style="color: #004400;">:</span>
	<span style="color: #004400;">@</span>echo Testing units<span style="color: #004400;">...</span>
	<span style="color: #004400;">@$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TIME</span><span style="color: #004400;">&#41;</span> erl <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ERL_LIB_FLAGS</span><span style="color: #004400;">&#41;</span> \
	<span style="color: #004400;">-</span>mnesia dir <span style="color: #CC2200;">'&quot;$(DATA_DIR)&quot;'</span> <span style="color: #004400;">-</span>mnesia debug <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MNESIA</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>noshell \
	<span style="color: #004400;">-</span>eval <span style="color: #CC2200;">&quot;<span style="color: #000099; font-weight: bold;">\</span>
	cover:compile_directory(<span style="color: #000099; font-weight: bold;">\&quot;</span>.<span style="color: #000099; font-weight: bold;">\&quot;</span>, [{i,<span style="color: #000099; font-weight: bold;">\&quot;</span>$(INCLUDE)<span style="color: #000099; font-weight: bold;">\&quot;</span>},{d,'NODEBUG'}]), <span style="color: #000099; font-weight: bold;">\</span>
	T = fun(X) -&gt; io:format(user, <span style="color: #000099; font-weight: bold;">\&quot;</span>~-20.s<span style="color: #000099; font-weight: bold;">\&quot;</span>, [X]), X:test() end, <span style="color: #000099; font-weight: bold;">\</span>
	[T(X) || X &amp;lt;- &quot;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #CC2200;">&quot;], <span style="color: #000099; font-weight: bold;">\</span>
	F = fun(X) -&gt; cover:analyse_to_file(X, <span style="color: #000099; font-weight: bold;">\&quot;</span>$(LOG)/<span style="color: #000099; font-weight: bold;">\&quot;</span> ++ <span style="color: #000099; font-weight: bold;">\</span>
	    atom_to_list(X) ++ <span style="color: #000099; font-weight: bold;">\&quot;</span>_coverage.html<span style="color: #000099; font-weight: bold;">\&quot;</span>, [html]) end, <span style="color: #000099; font-weight: bold;">\</span>
	[F(X) || X &amp;lt;- &quot;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #CC2200;">&quot;]. <span style="color: #000099; font-weight: bold;">\</span>
	&quot;</span> <span style="color: #004400;">-</span>s init stop<span style="color: #004400;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>more on eunit</title>
		<link>http://www.virtual-clouds.com/2008/10/6/more-on-eunit/</link>
		<comments>http://www.virtual-clouds.com/2008/10/6/more-on-eunit/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 21:32:10 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=6</guid>
		<description><![CDATA[the use of eunit is very easy and intuitive. in principle every function which ends with _test of arity 0 (i.e. no input arguments) will be automaticly exported by eunit. eunit will also create a function called test() which will call all tests functions which have been defined. this mechanism leaves the programmer with only <a href='http://www.virtual-clouds.com/2008/10/6/more-on-eunit/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>the use of eunit is very easy and intuitive. in principle every function which ends with _test of arity 0 (i.e. no input arguments) will be automaticly exported by eunit. eunit will also create a function called test() which will call all tests functions which have been defined. this mechanism leaves the programmer with only the actual test writing, and saves him/her the tedious wrappers and procedures. writing a test on a new module become something which take few seconds.</p>
<p>for example, the next function has its own testing function:</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">flip_sides</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Side</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">case</span> <span style="color: #45b3e6;">Side</span> <span style="color: #186895;">of</span>
		x <span style="color: #6bb810;">-&gt;</span> <span style="color: #006600;">o</span><span style="color: #6bb810;">;</span>
		o <span style="color: #6bb810;">-&gt;</span> <span style="color: #006600;">x</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">flip_sides_test</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	?<span style="color: #ff3c00;">assert</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">flip_sides</span><span style="color: #109ab8;">&#40;</span>x<span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">==</span> o<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	?<span style="color: #ff3c00;">assert</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">flip_sides</span><span style="color: #109ab8;">&#40;</span>o<span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">==</span> x<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>the testing function is invoked automatically by calling the test function of this module, e.g. mymodule:test(). the test function is supplied by the eunit framework, which takes every function that ends with _test() and add it to the testing list of that module.</p>
<p>a more advanced testing method is needed for testing the always loops that keep the state on the erlang module. few problems need to be solved in order to properly test those kind of loops:</p>
<ul>
<li> initial state loading.</li>
<li> external function calls.</li>
<li> check of the new state, after each event.</li>
<p></lu></p>
<p>the first problem can be solved by adding a new start function for debug use, which takes all the state variables of the always loop as parameters. this allows you to start the always loop in any state you want.</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% original start of arity/0</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% new function for debug of arity/2</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>  <span style="color: #ff3c00;">register</span><span style="color: #109ab8;">&#40;</span>?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">spawn</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% the state loop</span>
<span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">receive</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> stop<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> stopped<span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> reset<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>add<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">N</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span>module2:<span style="color: #ff3c00;">add</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">N</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> continue<span style="color: #109ab8;">&#41;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>the next problem is the call for external function, shown here as call for module2:add/2, i solved this by adding another parameter to the loop&#8217;s state in order to keep a reference to the called function. i have also added it to the start function.</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% original start of arity/0</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #186895;">fun</span> module2:<span style="color: #006600;">add</span><span style="color: #014ea4;">/</span><span style="color: #ff9600;">2</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% new function for debug of arity/2</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #ff3c00;">register</span><span style="color: #109ab8;">&#40;</span>?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">spawn</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% the state loop</span>
<span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">receive</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> stop<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> stopped<span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> reset<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>add<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">N</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">F</span><span style="color: #ff3c00;">unc</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">N</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> continue<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>adding a reference to the external function allows me to switch to a mocking function as desired. for the new state checking i have added a dump command to the always loop which return me the current state, so i can test it on my testing functions.</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% the state loop</span>
<span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">receive</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> stop<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> stopped<span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> reset<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> reset<span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>add<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">N</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">F</span><span style="color: #ff3c00;">unc</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">N</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> continue<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> dump<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> dump<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#125;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>last i&#8217;ll show the test function:</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">always_reset_test</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #45b3e6;">Fun</span> <span style="color: #014ea4;">=</span> <span style="color: #186895;">fun</span> callback_check_reset_mockup<span style="color: #014ea4;">/</span><span style="color: #ff9600;">2</span><span style="color: #6bb810;">,</span>
	<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span>x<span style="color: #6bb810;">,</span> o<span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> continue<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	<span style="color: #ff3c00;">rpc</span><span style="color: #109ab8;">&#40;</span>reset<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	?<span style="color: #ff3c00;">assert</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">rpc</span><span style="color: #109ab8;">&#40;</span>dump<span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">==</span> <span style="color: #109ab8;">&#123;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	<span style="color: #ff3c00;">stop</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>callback_check_reset_mockup(N, State) ->  void. % you can check match if applicable
</pre>
<p>that's it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2008/10/6/more-on-eunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lots of &#8216;e&#8217;s&#8230;</title>
		<link>http://www.virtual-clouds.com/2008/10/3/lots-of-es/</link>
		<comments>http://www.virtual-clouds.com/2008/10/3/lots-of-es/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 21:22:00 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[erlang]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=3</guid>
		<description><![CDATA[i have started off a new project, mostly based on erlang, and i have decided to post few of my observations and experiences which i pick along the way. i will start with edoc and eunit, both i have added to my project with zero effort, and got remarkable results. edoc produces automatic documentation for <a href='http://www.virtual-clouds.com/2008/10/3/lots-of-es/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.virtual-clouds.com/wp-content/uploads/2008/10/erlang.gif" alt="erlang" title="erlang" width="114" height="96" class="alignleft size-full wp-image-108" />i have started off a new project, mostly based on <a href="http://www.erlang.org/">erlang</a>, and i have decided to post few of my observations and experiences which i pick along the way. i will start with <a href="http://www.erlang.org/doc/apps/edoc/index.html">edoc </a>and <a href="http://svn.process-one.net/contribs/trunk/eunit/doc/overview-summary.html">eunit</a>, both i have added to my project with zero effort, and got remarkable results.</p>
<p>edoc produces automatic documentation for the project. i have just added the right code to my project makefile, and voula &#8211; instance documentation for my functions api. the code itself is:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">docs<span style="color: #004400;">:</span>
erl <span style="color: #004400;">-</span>noshell <span style="color: #004400;">-</span>eval <span style="color: #CC2200;">&quot;edoc:application($(APPNAME), <span style="color: #000099; font-weight: bold;">\&quot;</span>.<span style="color: #000099; font-weight: bold;">\&quot;</span>, [$(DOC_OPTS)])&quot;</span> <span style="color: #004400;">-</span>s init stop</pre></div></div>

<p>where:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">APPNAME <span style="color: #004400;">=</span> myappVSN <span style="color: #004400;">=</span> <span style="color: #CC2200;">0.1</span>
DOC_OPTS <span style="color: #004400;">=</span> <span style="color: #004400;">&#123;</span>def<span style="color: #004400;">,</span> <span style="color: #004400;">&#123;</span>version<span style="color: #004400;">,</span> <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">VSN</span><span style="color: #004400;">&#41;</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #004400;">&#125;</span><span style="color: #004400;">&#125;</span><span style="color: #004400;">,</span> no_packages</pre></div></div>

<p>eunit gives an easy way to add unit testing to the project, again, i have added few lines to my makefile:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">MODULES <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,%,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
check<span style="color: #004400;">:</span>
<span style="color: #004400;">@</span>for f in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do \
echo <span style="color: #000088; font-weight: bold;">$$</span>f<span style="color: #004400;">;</span> \
erl <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ERL_LIB_FLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>noshell <span style="color: #004400;">-</span>s <span style="color: #000088; font-weight: bold;">$$</span>f test <span style="color: #004400;">-</span>s init stop<span style="color: #004400;">;</span> \
done</pre></div></div>

<p>those few lines takes all the erl files on the current directory and run the test function for each module.</p>
<p>that&#8217;s it for the first time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2008/10/3/lots-of-es/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
