<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
 
 <title>khigia</title>
 
 <updated>2009-10-19T21:53:32+08:00</updated>
 <id />
 <author>
   <name>Ludovic Coquelle</name>
   <email>lcoquelle@gmail.com</email>
 </author>
 
 
 <link rel="self" href="http://feeds.feedburner.com/khigia/blog" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry>
   <title>It all started as a loop in bash</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/RvfiPSYI3hA/it-all-started-as-a-loop.html" />
   <updated>2009-10-07T00:00:00+08:00</updated>
   <id>/bash/2009/10/07/it-all-started-as-a-loop</id>
   <content type="html">&lt;p&gt;Once upon a time (and quite a few other times), I needed to start a process and watch it&amp;#8217;s status to restart it in case of crash (yeah, this kind of things still happens).&lt;/p&gt;
&lt;p&gt;It all start with a simple bash script:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;until $CMD
do
  echo "crashed! restart in 1 second"
  sleep 1
done&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then I needed to send alert in case of crash, to stop the process on request and to query the status.  At this point, I should have moved away from bash &amp;#8230; but I didn&amp;#8217;t. Worst than that, I stole idea on the web to add an &lt;span class="caps"&gt;HTTP&lt;/span&gt; &lt;span class="caps"&gt;API&lt;/span&gt; &amp;#8230; in bash, yes. Why not monit? not even half the fun!&lt;/p&gt;
&lt;p&gt;So now there is this big script, with the wonderfull name of &amp;#8220;runloop.sh&amp;#8221;, &lt;a href="http://github.com/khigia/bashful/blob/master/runloop.sh"&gt;hosted on github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Following are use examples.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;start&lt;br /&gt;
Start the command line and monitor the process from another background process. The &amp;#8220;myAppID&amp;#8221; is a simple identifier of the instance of the running program. This create files to log the pid of the app, of the monitor, and also one file with monitor logs. If myapp crash or stop with exit code different from 0, it is restarted.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;shell&amp;gt; ./runloop.sh start myAppID /usr/local/myapp/bin/myapp --be-nice&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
	&lt;li&gt;status&lt;br /&gt;
This print a message &amp;#8220;running&amp;#8221; or not, and exit with code 0 if running.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;shell&amp;gt; ./runloop.sh status myAppID&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
	&lt;li&gt;stop&lt;br /&gt;
Send the kill signal to process identified by myAppID.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;shell&amp;gt; ./runloop.sh stop myAppID&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;span class="caps"&gt;HTTP&lt;/span&gt;:&lt;br /&gt;
Direct browser to http://localhost:9000/myAppID to get status or to stop myAppID.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;shell&amp;gt; ./runloop.sh http&lt;/code&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/RvfiPSYI3hA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//bash/2009/10/07/it-all-started-as-a-loop.html</feedburner:origLink></entry>
 
 <entry>
   <title>Ubigraph view of pagerank result</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/RhozuJ_WVXU/ubigraph-with-pagerank.html" />
   <updated>2009-06-04T00:00:00+08:00</updated>
   <id>/ocaml/2009/06/04/ubigraph-with-pagerank</id>
   <content type="html">&lt;p&gt;This post is a sequel to the previous post about visualization of random graph through Ubigraph.&lt;/p&gt;
&lt;p&gt;This time, I implemented a very simple pagerank algo (&lt;a href="http://github.com/khigia/socnet/tree"&gt;functor Pr&lt;/a&gt;) to set the size of the vertices.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte -n 320 -ubi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="/images/rnd-graph-ubi-320-pr.jpg" style="width:16cm;" alt="" /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte -n 520 -ubi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="/images/rnd-graph-ubi-520-pr.jpg" style="width:16cm;" alt="" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/RhozuJ_WVXU" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//ocaml/2009/06/04/ubigraph-with-pagerank.html</feedburner:origLink></entry>
 
 <entry>
   <title>Random graph generation example</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/1yqhHXzgJOQ/random-social-graph-generation.html" />
   <updated>2009-05-30T00:00:00+08:00</updated>
   <id>/ocaml/2009/05/30/random-social-graph-generation</id>
   <content type="html">&lt;p&gt;Have been playing around with the &lt;em&gt;beautiful&lt;/em&gt; &lt;a href="http://ocamlgraph.lri.fr"&gt;ocamlgraph&lt;/a&gt; library. I also installed &lt;a href="http://code.google.com/p/xmlrpc-light"&gt;xmlrpc-light&lt;/a&gt; to draw graph through the free version of the &lt;a href="http://ubietylab.net/ubigraph"&gt;ubigraph&lt;/a&gt; server.&lt;/p&gt;
&lt;p&gt;I wrote a tool to generate some random graph. The goal is to render graph that have the same connectivity caracteristics as social networks. The generation algorithm is inspired of the forest fire model for graph generation (propagate links to neighboorhood recursively).&lt;/p&gt;
&lt;p&gt;The code is &lt;a href="http://github.com/khigia/socnet/tree"&gt;online&lt;/a&gt;. All is in single file &lt;em&gt;socnet.ml&lt;/em&gt;, but I use code from &lt;em&gt;xmlrpc-light&lt;/em&gt; library for Ubigraph calls. There is a &lt;em&gt;Builder&lt;/em&gt; module to augment the default builder of &lt;em&gt;ocamlgraph&lt;/em&gt; with a state; a special UbigraphBuilder to replicate the graph structure for rendering; and finally the algo to generate the graph is in Gen module.&lt;/p&gt;
&lt;p&gt;The result is a single binary:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte
  [-n &amp;lt;node-number&amp;gt;]
  [-gv] [-ubi]
  [-fwd &amp;lt;forward-factor&amp;gt;] [-bck &amp;lt;backward-factor&amp;gt;] [-bi &amp;lt;linking-back-factor&amp;gt;]
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
When creating an edge from a source node to some target node:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;forward factor is related to the probability to link source node to successors of a target node&lt;/li&gt;
	&lt;li&gt;backward factor is related to the probability to link source node to predecessors of a target node&lt;/li&gt;
	&lt;li&gt;linking back factor is related to probability to create an edge from target node to source node&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Following are some screenshots of results, although it is much more interesting to watch the construction steps though Ubigraph renderer.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte -n 12 -bi 0.0 -gv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="/images/rnd-graph-gv-12.jpg" style="width:16cm;" alt="" /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte -n 12 -gv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="/images/rnd-graph-gv-12-bi.jpg" style="width:16cm;" alt="" /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte -n 800 -bi 0.0 -ubi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="/images/rnd-graph-ubi-800.jpg" style="width:16cm;" alt="" /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
./socnet.byte -n 800 -ubi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="/images/rnd-graph-ubi-800-bi.jpg" style="width:16cm;" alt="" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/1yqhHXzgJOQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//ocaml/2009/05/30/random-social-graph-generation.html</feedburner:origLink></entry>
 
 <entry>
   <title>Lock-free shared memory: 1 writer, N readers</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/mstzwC0Ktms/lock-free-shared-memory-1writer.html" />
   <updated>2009-05-25T00:00:00+08:00</updated>
   <id>/cpp/2009/05/25/lock-free-shared-memory-1writer</id>
   <content type="html">&lt;p&gt;In recent projects I have been involved with, a lock-free shared memory pattern is used quite often. I would like to describe it here, and if anyone can tell me the name for this pattern, I&amp;#8217;ll be very much grateful.&lt;/p&gt;
&lt;p&gt;This technic I&amp;#8217;m going to describe can be used in the case of 1 writter and N readers. It shares some kind of idea from both a spin-lock and an &lt;span class="caps"&gt;STM&lt;/span&gt; (Software Transactional Memory) in the sense that the writer does not take a lock but write some kind of transaction state of the memory, and reader does not lock neither but keep reading in a loop (spin) until the transaction is coherent.&lt;/p&gt;
&lt;p&gt;All that will make more sense with some code (refer to note &lt;sup class="footnote"&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt; and &lt;sup class="footnote"&gt;&lt;a href="#fn2"&gt;2&lt;/a&gt;&lt;/sup&gt; for warning about this code; messing with memory model is very easy with lock-free stuffs). Suppose you have a shared data containing 2 values &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt;; first step is to add some kind of transaction markers:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
// beside of the data ...
// 2 transaction markers v1 and v2 are added to the memory
struct element_t {
  volatile uint v1;
  double x, y;
  volatile uint v2;
} elt;
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Next step is simple: as long as &lt;em&gt;v1&lt;/em&gt; is equal to &lt;em&gt;v2&lt;/em&gt;, the memory is in coherent state; else we don&amp;#8217;t know what the writer is doing and nothing should be read. So writer has to maintain those markers as follow:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
// writter thread use marker v1 to start a transaction
elt.v1 ++;
// does some data updates
elt.x = 42;
elt.y = elt.x * 12;
// and set marker v2 as end of transaction
elt.v2 ++;
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When the reader access the data, it has to make sure that v1 and v2 are equals &lt;strong&gt;and&lt;/strong&gt; do not change during the time reader access the memory. This can be done like following &lt;sup class="footnote"&gt;&lt;a href="#fn3"&gt;3&lt;/a&gt;&lt;/sup&gt;:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
// reader thread keep reading the memory ...
// until transaction markers are in "correct" state
uint m1,m2;
double x,y;
do {
  m1 = elt.v1;
  x = elt.x;
  y = elt.y;
  m2 = elt.v2;
} while(m1 != m2);
// at this point, x and y have a correct value
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s it!&lt;br /&gt;
So, what the name of this pattern?&lt;/p&gt;
&lt;p&gt;By the way, if you like to read about shared memory concurrency, make sure to read the &lt;a href="http://www.cilk.com/multicore-blog"&gt;Cilk++ blog&lt;/a&gt; , it&amp;#8217;s a gem ;).&lt;/p&gt;
&lt;p class="footnote" id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; The marker increment need to be an atomic operation, and you may want to use a memory barrier instruction in some cases.&lt;/p&gt;
&lt;p class="footnote" id="fn2"&gt;&lt;sup&gt;2&lt;/sup&gt; This code rely on operations order. In most of programming languages, order is never enforce by the language definition, and some compiler might try to reorder things (to improve cache or whatever). Even in C, the volatile does not protect the code. Only way I know to check this code: compile and test it! different optimization flag can result in different code. Check the generated code on your compiler/platform to make sure.&lt;/li&gt;&lt;/p&gt;
&lt;p class="footnote" id="fn3"&gt;&lt;sup&gt;3&lt;/sup&gt; Of course you need to handle manually how to follow pointer in your data.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/mstzwC0Ktms" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//cpp/2009/05/25/lock-free-shared-memory-1writer.html</feedburner:origLink></entry>
 
 <entry>
   <title>Adding a timeout to a shell command</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/FF3D5yX7PFk/adding-a-timeout-to-a-shell-command.html" />
   <updated>2009-04-24T00:00:00+08:00</updated>
   <id>/wp-import/general/2009/04/24/adding-a-timeout-to-a-shell-command</id>
   <content type="html">Quite a few times one or the other of my automation shell scripts got hang while running some external command (e.g. a remote shell command may hang if network is in weird state). For those cases where a stopped automation script could really hurt the system, I ended up writing a script wrapper that add a timeout to any command.&lt;br/&gt;

This is kind of heavy weight implementation: instead of running the command directly, this start a first process sleeping for the duration of the timeout, and execute the command in a background process, and finally return the result of the first finishing process! 3 processes: 1 working, 1 sleeping, 1 waiting ... but it helped me few times!&lt;br/&gt;

&lt;a href="http://gist.github.com/101192"&gt;Gisty code&lt;/a&gt;&lt;br/&gt;

&lt;script src="http://gist.github.com/101192.js"&gt;&lt;/script&gt;
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/FF3D5yX7PFk" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2009/04/24/adding-a-timeout-to-a-shell-command.html</feedburner:origLink></entry>
 
 <entry>
   <title>For the lost twitter sheeps</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/R_e-M0heEu4/for-the-lost-twitter-sheeps.html" />
   <updated>2009-04-10T00:00:00+08:00</updated>
   <id>/wp-import/general/2009/04/10/for-the-lost-twitter-sheeps</id>
   <content type="html">Tweet-tweet here, tweet-tweet there, here tweet, there tweet, ... everybody tweet! And you got to choose who to follow or you'll be quickly overwhelmed!&lt;br/&gt;
&lt;a href="http://mrtweet.net/"&gt;MrTweet &lt;/a&gt;can help you there by proposing you some tweets to follow. How can he achieve that? Through this blog post, let's focus on the subject of recommending twitter users to follow to existing user.&lt;br/&gt;
Disclamer: I have no accointance what's so ever with MrTweet, and absolutely no knowledge about it, nada; all the following are random thoughts; oh, and I have no accointance with &lt;a href="http://twitter.com/"&gt;Twitter &lt;/a&gt;neither!&lt;br/&gt;
Let say you have access to all the tweets of the world [1], and you can know who's following who on twitter. How would you look for new user to follow?
Obviously there are quite a few possibilities ... and some of them are probably yet to be invented. Traditionally, mining this kind of info can be done at 2 levels: (1) looking at the content and recommend to user U1 to follow user U2 if there is any correlation between tweets content of users U1 and U2; (2) second level is to look at the graph on connected communities and recommend user U1 to follow user U2 if they share some links in the graph.
On top of this there are many refinements in what can be done to mine such information: focusing and differenciating static data and dynamic aspects of user behaviours, mixing approaches of content and meta data, looking for time-series correlation ... this is a vast domain.&lt;br/&gt;
Following are some ideas about different way to implement MrTweet.
&lt;h2&gt;The UserRank dictature&lt;/h2&gt;
Using a Pagerank-like algorithm to explore the graph of followers, you can obtain a global UserRank for all the twitter users.&lt;br/&gt;
Why Pagerank? Well, this is probably not the best approach of the problem, as it extract a global knowledge of your data, where in this case we should focus on communities. But heck! I like PageRank, it's simple, and it's a good start to think about the problem. PageRank was the first &lt;a href="http://citeseer.ist.psu.edu/page98pagerank.html"&gt;scientific article&lt;/a&gt; that I study thoroughly, and it was  a ha-ha moment: simple to read, easy to understand, easy to implement ... computer science was possible! No need of linear algebra, matrix and eigenvector to understand it (it helps for the proof though :)). [2]&lt;br/&gt;
So how to apply Pagerank to "tweeterers"? Well, following is one way to do it.&lt;br/&gt;
For each user consider its followers as mark of interest. The algo define PageRank number Pr of user U as the weighted sum of the Pr of all its followers, where the weight is in inverse proportion of the number of people followed by the follower.&lt;br/&gt;
That is, with some notations to make it hopefully clearer:
&lt;ul&gt;
	&lt;li&gt;Let Pr(U) be the PageRank of user U;&lt;/li&gt;
	&lt;li&gt;Let Fo(U) be the set of all user that U is following, and [Fo(U)] its cardinality;&lt;/li&gt;
	&lt;li&gt;Let Fi(U) be the set of all user that are following U;&lt;/li&gt;
	&lt;li&gt;PageRank is: Pr(Ux) = Sum(Pr(Un)/[Fo(Un)]), for all  Un in Fi(Ux).&lt;/li&gt;
&lt;/ul&gt;
Thus Pr is high if the user is followed by users which have a high Pr and are not following everybody! Easy enough but wait ... how to get the Pr of the followers? this is kind of a recursive definition!&lt;br/&gt;
The beauty of the PageRank algo is that it propose an simple iterative solution to solve this problem: asume first that everybody as a Pr=Pr_0 of 1/N (N is the number of users, this give everybody a fair starting value), compute the new Pr_1 of each user using Pr_0 assumption, then compute the Pr_2 of each user given your Pr_1 assumption ... and iterate a few more times until the Pr stabilize, usually after few computations only (this is not magic but math ... which sometimes looks alike). If you like matrix and linear algebra, you can write the whole process as a loop which multiply a the vector of all PageRank by a square matrix of all 'follow-relations'.&lt;br/&gt;
Now, all we have is a Pr for each user? then what? Who shall I follow? Well, use your network to discover it!&lt;br/&gt;
Take all the people you are following, grab all the people they follow themselves, and remove your own sibling from this big set of people; sort them by Pr and you'll get to follow the most "popular" people linked to your network.&lt;br/&gt;
We have a UserRank algo to recommend people to follow to any twitter user! Well, all this rely on assumption that being followed give the user some importance. And I don't know if this works, I haven't tried it! Maybe it can be done with google API and the twitter page of the user ;)&lt;br/&gt;
Let explore another algo with another kind of idea.
&lt;h2&gt;Following the Slope&lt;/h2&gt;
In fact, what we're looking for with MrTweet, is the same kind of recommendation as Amazon made popular: "users who like this also like that". Using the same meta-data as previously (the graph of followers), we can rephrase it as "user who follow Ux and Uy are also following Uz".&lt;br/&gt;
Algo to solve those problems are usually classified as recommender systems (see the NetFlix for importance of those kind of algo). A big problem of those solution for web application is often scalability and dynamic nature. But let's pick one such recommender system and see what can be done for MrTweet problem.&lt;br/&gt;
No surprise, let's look at &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.60.4503"&gt;SlopeOne&lt;/a&gt; algorithm. The &lt;a href="http://en.wikipedia.org/wiki/Slope_One"&gt;wikipedia page&lt;/a&gt; explain it very simply and I surely can't do better. All we need to do is map the data to our problem. Let say that if user U1 follow user U2, this means user U1 rate user U2 with weight 1. Doing so, we'll have only rating of weight 1. This is ok for SlopeOne to give some result though.&lt;br/&gt;
The main difference with previous method of UserRank is that this is not a global analysis of all the users but rely more on the network of the user to which you want to do the recommendation.&lt;br/&gt;
Wanna real rating value to feed your SlopeOne algo? well, why not use the UserRank you defined previously as the rating value, and compute the SlopeOne prediction based on that? thus you would get as recommendation not the most popular user linked to your network but the most popular user liked by your network! Not so bad! Maybe yes, maybe not ... need to be tested!
&lt;h2&gt;More than a graph?&lt;/h2&gt;
We've been looking at the graph of followers, which give recommendatons based on "neighborhood". Let's open the problem a bit more ...
&lt;ul&gt;
	&lt;li&gt;instead of using followers, we can look at the graph of replies&lt;/li&gt;
	&lt;li&gt;why not look at the tweet content? we could check correlation in keyword, or in the URL (even following the URL)?&lt;/li&gt;
	&lt;li&gt;why not cross data from twitter with data from other network? ... and I'm going to read about this just here: http://33bits.org/2009/03/19/de-anonymizing-social-networks :)&lt;/li&gt;
&lt;/ul&gt;
I don't know you, but this kind of problem delight me. But after all this thinking and no action, I'm now going to write some real code to do more than think about algo ;).&lt;br/&gt;
[1] With N millions users, 7 tweets a day, 140 bytes a tweet in raw format ... storage is not that huge, even for few years. How many twitter users? where does seven come from? who care! engineers only need order of magnitude and units!&lt;br/&gt;
[2] Pagerank is closely related to the hub and authorities: &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.120.3875"&gt;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.120.3875&lt;/a&gt; [3]&lt;br/&gt;
[3] I know, all those ref are "old" :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/R_e-M0heEu4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2009/04/10/for-the-lost-twitter-sheeps.html</feedburner:origLink></entry>
 
 <entry>
   <title>TAOCP vs. Code Complete</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/oGxVcHmLXKc/taocp-vs-code-complete.html" />
   <updated>2009-01-10T00:00:00+08:00</updated>
   <id>/wp-import/general/2009/01/10/taocp-vs-code-complete</id>
   <content type="html">Surprising! as of now, in my experiences of software engineer, I met more people that read/know about &lt;a href="http://www-cs-faculty.stanford.edu/~knuth/taocp.html"&gt;TAOCP&lt;/a&gt; than people who read &lt;a href="http://cc2e.com/"&gt;Code Complete&lt;/a&gt;.&lt;br/&gt;
It may be a probability accident (I kind of remember that probabilities and small numbers are not good friends). It may also be influenced by my fields of experiences. But assuming this is real (i.e. programmers know more about TOACP), it's doesn't seems right.&lt;br/&gt;
I consider TAOCP as a reference to write efficient code; Code Complete is a reference to write good software (eventually being a product maintained by a team). Both are important, but the first one being used way less often!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/oGxVcHmLXKc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2009/01/10/taocp-vs-code-complete.html</feedburner:origLink></entry>
 
 <entry>
   <title>Back to roots ... with physics!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/rmIIH_zh0Jc/back-to-roots-with-physics.html" />
   <updated>2009-01-07T00:00:00+08:00</updated>
   <id>/wp-import/cpp/2009/01/07/back-to-roots-with-physics</id>
   <content type="html">This blog is not completely abandoned ... I'm just buzy lazy those days.&lt;br/&gt;
Just to relate my brief come back to roots: doing physics simulation in 3D ;).&lt;br/&gt;
I've been playing with &lt;a title="Irrlicht" href="http://irrlicht.sourceforge.net/"&gt;Irrlicht&lt;/a&gt; as 3D framework. It's good, not to complex. But the API is not always easy (you're forced to use the irrlicht not-automatic counting ref). I haven't found doc about coordinate systems (orientation and angle's units) but it's using common practices in game engine. It's pretty fast, and the simple included demos help a lot to get started (Ogre3D don't come with simple examples).&lt;br/&gt;
For the physics engine, I've used &lt;a title="Bullet" href="http://www.bulletphysics.com/Bullet/wordpress/"&gt;Bullet&lt;/a&gt;, and it's really pleasant to use! and result are great! I only quickly went through some part of the code, and it's great code, I think I will learn quite a few tricks of this code (e.g. how to avoid conditional branch ('if') to select between 2 unsigned integers ... and it even can be usefull for efficiency on some processor like Cell (maybe related to parallelism and pipelining?). No really, this is beautiful code, and if you just want to play a little bit with physics, using Bullet directly is more fun than &lt;a title="PAL" href="http://www.adrianboeing.com/pal/index.html"&gt;PAL&lt;/a&gt; (Physic Abstraction Layer).&lt;br/&gt;
I'll post the code when/if my Domino Rally simu is done :) ... but without sound it's not good.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/rmIIH_zh0Jc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/cpp/2009/01/07/back-to-roots-with-physics.html</feedburner:origLink></entry>
 
 <entry>
   <title>Terminology: radix, Patricia, TRIE and tree</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/2VAZIH32hEw/terminology-radix-patricia-trie-and-tree.html" />
   <updated>2008-11-30T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/11/30/terminology-radix-patricia-trie-and-tree</id>
   <content type="html">I took some time to get the terminology: radix tree/trie, patricia tree/trie ... it's all the same, really:
&lt;ul&gt;
	&lt;li&gt;A trie is a multi-way tree;&lt;/li&gt;
	&lt;li&gt;I guess radix term replaced the Patricia appellation because it sounds more generic (not specific to information retrieval);&lt;/li&gt;
	&lt;li&gt;And in the case of radix trie, if you use the binary representation of the key, you have an alphabet of 2 and the trie become a 2-ways tree, thus radix tree :P&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/2VAZIH32hEw" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/11/30/terminology-radix-patricia-trie-and-tree.html</feedburner:origLink></entry>
 
 <entry>
   <title>String specific data-structure: set and map</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Z0hHPmQkrkI/string-specific-data-structure-set-and-map.html" />
   <updated>2008-08-09T00:00:00+08:00</updated>
   <id>/wp-import/ocaml/2008/08/09/string-specific-data-structure-set-and-map</id>
   <content type="html">Lately I've been playing a bit ... well, that's a programmer kind of game: I wrote yet other implementations (with yet other bugs I assume) of some classic data-structures, in Ocaml.&lt;br/&gt;
Those are all about string set or string map, and are purely functional (thus persistent).&lt;br/&gt;
The code is in the project ocaml-stringset (&lt;a href="http://github.com/khigia/ocaml-stringset/tree/master"&gt;http://github.com/khigia/ocaml-stringset/tree/master&lt;/a&gt;). There is a TST (ternary search tree), a Collapsed TST, a Trie (&lt;a href="http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504"&gt;bootstrap version of Chris Okasaki&lt;/a&gt;) and maybe other will be added. Most of the code is in file/module StringSet so it is easy to embed in a project. There is one example file for each datastructure (as well as some unit test ... and the unit tests of TST iss pretty bad as it test the internal structure, not the API).&lt;br/&gt;
Haven't been as far as doing stress tests though it would be nice to compare the different behaviours.&lt;br/&gt;
&lt;strong&gt;Update:&lt;/strong&gt; those algo are implemented for string, but we could certainly provide a generic implementation for any datatype that is iterable collection and whose items are comparable. I may try to make some generic version later on.&lt;br/&gt;
&lt;strong&gt;Update:&lt;/strong&gt; most of those tree algo implementation are NOT tail recursive; this would probably need continuations ... I'll add this if/when needed (in production environment, it should probably be done anyway except if the use case is restricted and ensure a limit in recursion depth).&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Z0hHPmQkrkI" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ocaml/2008/08/09/string-specific-data-structure-set-and-map.html</feedburner:origLink></entry>
 
 <entry>
   <title>Generate all pair permutations in (not really) random order (and space efficiently)</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/jwqYtp_DZG8/generate-all-pair-permutations-in-not-really-random-order-and-space-efficiently.html" />
   <updated>2008-08-07T00:00:00+08:00</updated>
   <id>/wp-import/ocaml/2008/08/07/generate-all-pair-permutations-in-not-really-random-order-and-space-efficiently</id>
   <content type="html">&lt;em&gt;(that time I learnt the lesson: never promise what the next post will be about coz I often not deliver)&lt;/em&gt;&lt;br/&gt;
Optimization algo need to explore the space of solutions, and this exploration is a major part of the algo! Let's focus on one simple case: exploring in random order two finite dimensions. For example, let two integer variables, V1 taking value in interval [1, 100] and V2 taking value in interval [1, 20]: how to explore all the possible pairs (v1,v2) in random order?&lt;br/&gt;
A simple (almost-)solution is given by the following python code:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
[(e1,e2) for e1 in shuffle(range([1,100)), for e2 in shuffle(range(1,20))]
&lt;/code&gt;&lt;/pre&gt;
which is in fact the cartesian product of the shuffles of V1 and V2 intervals ... but this is ordered by values of the first shuffle and thus not random.&lt;br/&gt;
OK, now is the bad news: I have no solution completely space efficient to propose. My best effort is a solution which compute at least two shuffles, one on each dimension (kind of O(n + m) for space) and is even not random ... just random enough for most of the cases :P&lt;br/&gt;
So how? the solution is describe in this post &lt;a href="http://weblog.raganwald.com/2007/02/haskell-ruby-and-infinity.html"&gt;http://weblog.raganwald.com/2007/02/haskell-ruby-and-infinity.html&lt;/a&gt; and especialy the section about the tabular view of the cartesian product. Did you read it? so the proposed solution is to navigate the cross-product table along its diagonal instead of row by row ... simply smart isn't it? It give "impression" of randomness :P&lt;br/&gt;
Ocaml code for this algo is here: &lt;a href="http://github.com/khigia/ocaml-anneal/tree/master/walks.ml"&gt;http://github.com/khigia/ocaml-anneal/tree/master/walks.ml&lt;/a&gt; (function &lt;span class="n"&gt;pair_permutation_random_seq); &lt;/span&gt;It uses extensively an ad-hoc stream implementation (Seq module) to perform the walk lazyly. It was a good example to test the stream implementation!
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/jwqYtp_DZG8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ocaml/2008/08/07/generate-all-pair-permutations-in-not-really-random-order-and-space-efficiently.html</feedburner:origLink></entry>
 
 <entry>
   <title>Simulated annealing in OCaml</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/FFQRLhyc5GQ/simulated-annealing-in-ocaml.html" />
   <updated>2008-06-11T00:00:00+08:00</updated>
   <id>/wp-import/ocaml/2008/06/11/simulated-annealing-in-ocaml</id>
   <content type="html">I've been using this &lt;a href="http://psychicorigami.com/2007/06/28/tackling-the-travelling-salesman-problem-simmulated-annealing/"&gt;python implementation&lt;/a&gt; of &lt;a href="http://en.wikipedia.org/wiki/Simulated_annealing"&gt;simulated annealing&lt;/a&gt; to deduce Singapore bus service from a database of bus stops (see &lt;a href="http://khigia.wordpress.com/2008/05/24/sg-bus-services-map/"&gt;previous&lt;/a&gt; &lt;a href="http://khigia.wordpress.com/2008/05/28/sg-bus-routes-following/"&gt;post&lt;/a&gt;s about Google Map API).&lt;br/&gt;
I wanted to play a little bit more with this algo and decided to port it to OCaml: you can find &lt;a href="http://github.com/khigia/ocaml-anneal/tree/master"&gt;the code on GitHub&lt;/a&gt;.&lt;br/&gt;
As a first try, I wrote a direct code translation. Only few points differ:
&lt;ul&gt;
	&lt;li&gt;The OCaml code use a &lt;a href="http://github.com/khigia/ocaml-anneal/tree/master/seq.ml"&gt;stream implementation&lt;/a&gt; (lazy list) ... (mostly equivalent to my &lt;a href="http://khigia.wordpress.com/2007/05/07/44/"&gt;previous&lt;/a&gt; Erlang implementation).&lt;/li&gt;
	&lt;li&gt;The OCaml code uses array structure where Python uses list.&lt;/li&gt;
	&lt;li&gt;The OCaml implementation of function reversed_section do only one array reverse in all cases.&lt;/li&gt;
&lt;/ul&gt;
Result is quite ok. Without any optimization on the algo, the OCaml native code performed quite faster (around 10 times faster), meaning that solving the TSP problem for SG bus services took 40 minutes for OCaml version where the Python code ran for hours (of course we could improve this version too).&lt;br/&gt;
The algo itself can be improve (I guestimate the time for SG map problem can be reduce by one more order of magnitude with the same simulated annealing approach).&lt;br/&gt;
But in coming post (code is there, need time to clean it), I'll be looking at other interesting problems I found inside this one, especially on how to walk in solutions space in quasi-random order.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/FFQRLhyc5GQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ocaml/2008/06/11/simulated-annealing-in-ocaml.html</feedburner:origLink></entry>
 
 <entry>
   <title>SG bus routes ... following</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Aog-U_QqoyQ/sg-bus-routes-following.html" />
   <updated>2008-05-28T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/05/28/sg-bus-routes-following</id>
   <content type="html">This post is a following to the &lt;a href="http://khigia.wordpress.com/2008/05/24/sg-bus-services-map/"&gt;previous post about drawing SG bus route&lt;/a&gt; with google map API.
&lt;h3&gt;Status of the system&lt;/h3&gt;
This is for now only a toy demo, all in a single javascript document that draw the map when loaded (the javascript file is generated from a KML file by a python program that also computes the bus service routes).
&lt;h3&gt;Toward drawing all the bus services ...&lt;/h3&gt;
Drawing all the bus services on the same map not only is *very heavy* for the browser (at least for firefox, and its SVG renderer) but also give very little information (it is too much data at one time).&lt;br/&gt;
See by yourself:
&lt;p style="text-align:center;"&gt;&lt;a href="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-all_inner.jpg"&gt;&lt;img class="alignnone size-medium wp-image-101 aligncenter" src="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-all_inner.jpg?w=300" alt="" width="300" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;
Even zooming (on Dhoby Ghaut station):
&lt;p style="text-align:center;"&gt;&lt;a href="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-all-zoom_inner.jpg"&gt;&lt;img class="alignnone size-medium wp-image-102 aligncenter" src="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-all-zoom_inner.jpg?w=300" alt="" width="300" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br/&gt;
&lt;h3&gt;What could be done ...&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;To solve the problem of too many services displayed at same time, definitively a good UI could improve usability.
What I have in mind is a kind of UI which enable to select which services to display ... but maybe something better can be done like auto-selection of services to display depending of zoom factor or user itinary?&lt;/li&gt;
	&lt;li&gt;The previous point could also help to not send all the data to the client (in order to save bandwith).&lt;/li&gt;
	&lt;li&gt;Automatic route simplification: on one route, when adjacent stops are "too close" to each other, we could remove one of them on the drawing (which would make it lighter, and also remove some artifact like tiny wigzag caused by stop on the opposite side of the road).&lt;/li&gt;
	&lt;li&gt;Adding some constraints manually (editing few distance between some stops) to correct some wrong path.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;More?&lt;/h3&gt;
As in the previous post conclusions, I think a mashup of existing itinery service to display the itinery on a map could be quite interesting.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Aog-U_QqoyQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/05/28/sg-bus-routes-following.html</feedburner:origLink></entry>
 
 <entry>
   <title>SG bus services map</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/U8qUo0kcqYQ/sg-bus-services-map.html" />
   <updated>2008-05-24T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/05/24/sg-bus-services-map</id>
   <content type="html">Playing with the DB of SG bus stop &lt;a href="http://khigia.tumblr.com/post/35900924/found-a-db-of-singapore-bus-stops-3732-stops"&gt;locations&lt;/a&gt; and google map API.&lt;br/&gt;
My goal is to try to draw the route of the bus services ... but the DB has no info about the order of the stops per service (there is info of which services stop for each bus stop). Following are some experiments, with display about bus service 124.&lt;br/&gt;
First try was kind of funny (not unexpected!) as I draw the bus route "as stops are found in DB" ... which apparently is from left to right:
&lt;p style="text-align:center;"&gt;&lt;a href="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-124_inner.jpg"&gt;&lt;img class="alignnone size-medium wp-image-96 aligncenter" src="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-124_inner.jpg?w=300" alt="" width="300" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;
So, to get a better idea of the bus route, I'm trying to draw the shortest path ... better and even quite enough:
&lt;p style="text-align:center;"&gt;&lt;a href="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-124-shortest_inner.jpg"&gt;&lt;img class="alignnone size-medium wp-image-97 aligncenter" src="http://khigia.files.wordpress.com/2008/05/screenshot-sgbus-124-shortest_inner.jpg?w=300" alt="" width="300" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;
But of course this is inexact map as:
&lt;ol&gt;
	&lt;li&gt;this shortest route uses all bus stops without taking care of which ones are on the way to go or the way to go back (this data is not in my DB);&lt;/li&gt;
	&lt;li&gt;the length of the path does not depend of the road ... those are only straight lines!&lt;/li&gt;
&lt;/ol&gt;
But anyway, this give a better view of the bus service than nothing or a guide book of bus stop names ...&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/U8qUo0kcqYQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/05/24/sg-bus-services-map.html</feedburner:origLink></entry>
 
 <entry>
   <title>screenshot-sgbus-124_inner</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/8VOLVvI-JQM/screenshot-sgbus-124_inner.html" />
   <updated>2008-05-24T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/05/24/screenshot-sgbus-124_inner</id>
   <content type="html">&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/8VOLVvI-JQM" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/05/24/screenshot-sgbus-124_inner.html</feedburner:origLink></entry>
 
 <entry>
   <title>screenshot-sgbus-124-shortest_inner</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/3Y2fUFJtA44/screenshot-sgbus-124-shortest_inner.html" />
   <updated>2008-05-24T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/05/24/screenshot-sgbus-124-shortest_inner</id>
   <content type="html">&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/3Y2fUFJtA44" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/05/24/screenshot-sgbus-124-shortest_inner.html</feedburner:origLink></entry>
 
 <entry>
   <title>erlocaml wc map-reduce example</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Lq-qh4chAd8/erlocaml-wc-map-reduce-example.html" />
   <updated>2008-05-20T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/05/20/erlocaml-wc-map-reduce-example</id>
   <content type="html">New example in ocamerl lib of &lt;a href="http://code.google.com/p/erlocaml/"&gt;erlocaml&lt;/a&gt; project: a tiny map-reduce-like (1) word-count program (word-count is the simple example &lt;a href="http://www.michael-noll.com/wiki/Writing_An_Hadoop_MapReduce_Program_In_Python"&gt;often&lt;/a&gt; &lt;a href="http://code.google.com/edu/parallel/mapreduce-tutorial.html"&gt;used&lt;/a&gt; to illustrate map-reduce principle).&lt;br/&gt;
&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_node_wc.ml?r=51"&gt;First part&lt;/a&gt; of this example is an ocaml distributed erlang node [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_node_wc.ml?r=51#52"&gt;l52&lt;/a&gt;]. It is composed of one permanent registered ('wc') mbox [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_node_wc.ml?r=51#40"&gt;l40&lt;/a&gt;] which upon request create other mboxes implementing the mappers [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_node_wc.ml?r=51#19"&gt;l19&lt;/a&gt;] (on request, a mapper read a text file [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_node_wc.ml?r=51#8"&gt;l8&lt;/a&gt;] and send it word by word to reducer [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_node_wc.ml?r=51#29"&gt;l29&lt;/a&gt;]).&lt;br/&gt;
&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_wc.erl?r=51"&gt;Second part&lt;/a&gt; of this map-reduce example is an erlang module implementing two functionalities. One of them is the reduce part implementation [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_wc.erl?r=51#34"&gt;l34&lt;/a&gt;] done by a process which accept messages from mappers and update a dictionary accordingly.
Second responsibility of this module is orchestration of the map-reduce flow [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_wc.erl?r=51#90"&gt;l90&lt;/a&gt;], consisting of running all mappers [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_wc.erl?r=51#66"&gt;l66&lt;/a&gt;], waiting end of all those executions [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_wc.erl?r=51#79"&gt;l79&lt;/a&gt;], and collecting result of all reducers [&lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/ex/ex_wc.erl?r=51#95"&gt;l95&lt;/a&gt;].&lt;br/&gt;
Assuming EPMD is running, &lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/test/wc.sh?r=51"&gt;this script&lt;/a&gt; run an ocaml node and an erlang node, and run a simple map-reduce to count words in two test files.&lt;br/&gt;
As usual, not sure it's a useful example, but it was sure fun to write :)&lt;br/&gt;
&lt;em&gt;(1) this is not a map-reduce lib ... there is no failure case taken care of, processes pipe is mostly done through messages over network (while map-reduce is mainly meant to use an efficient filesystem based communication), etc!&lt;/em&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Lq-qh4chAd8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/05/20/erlocaml-wc-map-reduce-example.html</feedburner:origLink></entry>
 
 <entry>
   <title>Ocamerl - Erlang ... echo-ing in shells</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/SMPtInxlvV4/ocamerl-erlang-echo-ing-in-shells.html" />
   <updated>2008-05-13T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/05/13/ocamerl-erlang-echo-ing-in-shells</id>
   <content type="html">Little intro step-by-step to the ocaml-erlang message exchange mechanism offered by ocamerl (a lib of erlocaml).&lt;br/&gt;
Subject of the following code is a wonderfull application ... named "echo server"!
&lt;ol&gt;
	&lt;li&gt;In the interpretor shell of ocaml, we create a hidden erlang node and an activity to echo all received message (both on console as well as in respond to the caller).&lt;/li&gt;
	&lt;li&gt;In the erlang interpretor shell, we send few message and compare them to the received ones.&lt;/li&gt;
&lt;/ol&gt;
The following assumes code is running on machine "comp1".&lt;br/&gt;
Ocaml shell:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
(* getting Ocamerl available in toplevel *)
ocaml&gt; #use "topfind";; (* ocamerl used findlib for install *)
ocaml&gt; #thread;; (* ocamerl is multithreaded app *)
ocaml&gt; #require "ocamerl";;
(* creating/declaring a node, assuming epmd is running *)
ocaml&gt; let o1 = Ocamerl.Enode.run "o1" ~cookie:"cookie";;
val o1 : Ocamerl.Enode.t = &lt;abstr&gt;
(* creating/declaring a mbox, equivalent of erlang process *)
ocaml&gt; let m = Ocamerl.Enode.create_mbox o1;;
val m : Ocamerl.Enode.Mbox.t = &lt;abstr&gt;
ocaml&gt; Ocamerl.Enode.register_mbox o1 m "echoer";; (* give it a name *)
- : unit = ()
ocaml&gt; Ocamerl.Enode.Mbox.create_activity m (fun msg -&gt; match msg with
    | Ocamerl.Eterm.ET_tuple [|pid; any;|] -&gt;
        Printf.eprintf "MSG:%s\n%!" (Ocamerl.Eterm.to_string msg);
        Ocamerl.Enode.send o1 pid any
    | _ -&gt;
        () (* drop unexpected msg *)
);;
- : unit = ()
&lt;/code&gt;&lt;/pre&gt;
Erlang shell:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
# starting erlang node with same cookie
erl -sname e1 -setcookie cookie
% check connection
erl&gt; pong = net_adm:ping(o1@comp1).
pong
% utility to print whatever is in message queue
erl&gt; F = fun() -&gt; receive W -&gt; io:format("got back: ~w~n", [W]) after 1 -&gt; error end end.
#Fun&lt;erl_eval.20.67289768&gt;
% some tests ... send data, received it back
erl&gt; {echo1, o1@comp1} ! {self(), {1,2,"test"}}.
{&lt;0.37.0&gt;,{1,2,"test"}}
erl&gt; F().
got back: {1,2,[116,101,115,116]}
ok
% in the mean time, ocaml shell also display the data
&lt;/code&gt;&lt;/pre&gt;
That's it! A wonderfull echo server :)&lt;br/&gt;
Amongst things on the to-do list:
&lt;ul&gt;
	&lt;li&gt;Should not have to create a mbox and set its activity separately (need some wrapper)&lt;/li&gt;
	&lt;li&gt;Could have an onode ocaml toplevel which run one node by default and offer direct interface (e.g. "send").&lt;/li&gt;
&lt;/ul&gt;
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/SMPtInxlvV4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/05/13/ocamerl-erlang-echo-ing-in-shells.html</feedburner:origLink></entry>
 
 <entry>
   <title>Erlang to call an Ocaml seam carving lib</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/tt8a67BqZuI/erlang-to-call-an-ocaml-seam-carving-lib.html" />
   <updated>2008-05-10T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/05/10/erlang-to-call-an-ocaml-seam-carving-lib</id>
   <content type="html">Yet another useless example for &lt;a href="http://code.google.com/p/erlocaml"&gt;erlocaml&lt;/a&gt;, but this time it is not completely silly ... it does something :)&lt;br/&gt;
In fact the project &lt;a href="http://github.com/khigia/eocarve/tree/master"&gt;eocarve&lt;/a&gt; uses:
&lt;ul&gt;
	&lt;li&gt;the &lt;a href="http://code.google.com/p/erlocaml/wiki/OcamerlIntro"&gt;ocamerl&lt;/a&gt; library (which got a &lt;a href="http://code.google.com/p/erlocaml/source/browse/trunk/lib/ocamerl/Makefile"&gt;makefile install rule&lt;/a&gt; for the occasion);&lt;/li&gt;
	&lt;li&gt;the &lt;a href="http://eigenclass.org/hiki/seam-carving-in-ocaml"&gt;seamcarving&lt;/a&gt; library provided by mce (thanks!) (it's LGPL so the full code can be found in eocarve).&lt;/li&gt;
&lt;/ul&gt;
Idea is simple: an ocaml node run and provide a API for Erlang node to call the seamcarving library. See &lt;a href="http://github.com/khigia/eocarve/wikis"&gt;eocarve wiki&lt;/a&gt; for details/example.&lt;br/&gt;
Aim of this project was mainly to demonstrate use of ocamerl lib ... however it may be usefull for an Erlang web app which would need seamcarving (heavy weight for CPU!). Had fun to integrate those lib in same app.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/tt8a67BqZuI" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/05/10/erlang-to-call-an-ocaml-seam-carving-lib.html</feedburner:origLink></entry>
 
 <entry>
   <title>Tiny progress on erlocaml</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/kGxvzSNFQX4/tiny-progress-on-erlocaml.html" />
   <updated>2008-05-06T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/05/06/tiny-progress-on-erlocaml</id>
   <content type="html">Minor updates for &lt;a href="http://code.google.com/p/erlocaml/"&gt;erlocaml&lt;/a&gt; (more exactly on &lt;a href="http://code.google.com/p/erlocaml/wiki/OcamerlIntro"&gt;ocamerl&lt;/a&gt;) ... mostly code cleaning and minor refactoring!&lt;br/&gt;
Only one new feature: ability for Erlang processes to send message to unregistered ocaml processes. An example of that is "ex_node_mult" which generalize "ex_node_double" by dynamically creating ocaml process to perform a multiplication ... yep I know, not very useful&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
% erlang code using the ocaml node
{byn, OcamlNode} ! {self(), 2},
By2 = receive M -&gt; M after 1 -&gt; error,
{byn, OcamlNode} ! {self(), 3},
By3 = receive M -&gt; M after 1 -&gt; error,
P1 = make_ref(),
P2 = make_ref(),
By2 ! {self(), P1, 21},
By3 ! {self(), P1, 21},
ok = receive {P1, 42} -&gt; ok after 1 -&gt; error end,
ok = receive {P2, 63} -&gt; ok after 1 -&gt; error end
&lt;/code&gt;&lt;/pre&gt;
With this feature, ocamerl begin to be usable ... and that's exactly what I will be doing next: experiment with more useful (at least less silly) examples! Some ideas are:
&lt;ul&gt;
	&lt;li&gt;tiny mapreduce example with ocaml workers (erlang doing the network part);&lt;/li&gt;
	&lt;li&gt;using the ocaml image processing lib from erlang (not best example as lot of data need to be exchange ... this is task to be solved for future erlocaml development);&lt;/li&gt;
	&lt;li&gt;others???&lt;/li&gt;
&lt;/ul&gt;
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/kGxvzSNFQX4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/05/06/tiny-progress-on-erlocaml.html</feedburner:origLink></entry>
 
 <entry>
   <title>me me Euler Pb1: looking at the data (and fun with python)</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/UdJAMXydl4Q/me-me-euler-pb1-looking-at-the-data-and-fun-with-python.html" />
   <updated>2008-04-25T00:00:00+08:00</updated>
   <id>/wp-import/python/2008/04/25/me-me-euler-pb1-looking-at-the-data-and-fun-with-python</id>
   <content type="html">Google for it, Euler problem #1 has got a lot of solution implementations. Most of them use similar algo: produce the list of all numbers in the range [0-1000], filter only number divisible by 3 or 5, and compute the sum. This is perfectly fine, and it's wonderfull to code when your language allow some kind of lazy list (default in Haskell, or often called stream library in other language).&lt;br/&gt;
But can we construct the sequence of "number divisible by 3 and 5" directly?&lt;br/&gt;
Let's have a look at what this sequence looks like:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
m = 42
l = sorted(list(set(range(0, m, 3) + range(0, m, 5))))
l
[0, 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30, 33, 35, 36, 39, 40]
&lt;/code&gt;&lt;/pre&gt;
Well ... cannot see a pattern ... let's look at the sequence of difference between 2 consecutive numbers:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
map(lambda (x,y): y-x, zip(l, l[1:]))
[3, 2, 1, 3, 1, 2, 3, 3, 2, 1, 3, 1, 2, 3, 3, 2, 1, 3, 1]
&lt;/code&gt;&lt;/pre&gt;
Here we go ... I have no idea why, but seems that we can construct the sequence using the list of increment 3,2,1,3,1,2,3 (same with m=300).&lt;br/&gt;
And then, here come a different python solution:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
from itertools import cycle, takewhile
def succ(b, inc):
  while True:
    b += inc.next()
    yield b
sum(takewhile(lambda x: x &lt; 1000, succ(0, cycle([3,2,1,3,1,2,3]))))
&lt;/code&gt;&lt;/pre&gt;&lt;br/&gt;
By the way, there must be a mathematical solution to this first problem, some kind of magic formula ... any pointer?
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/UdJAMXydl4Q" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/python/2008/04/25/me-me-euler-pb1-looking-at-the-data-and-fun-with-python.html</feedburner:origLink></entry>
 
 <entry>
   <title>ocaml vs. F# for big integer ... surprising performance test!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/l9z8Wa4F8TM/ocaml-vs-f-for-big-integer-surprising-performance-test.html" />
   <updated>2008-03-30T00:00:00+08:00</updated>
   <id>/wp-import/fsharp/2008/03/30/ocaml-vs-f-for-big-integer-surprising-performance-test</id>
   <content type="html">Was inspired by &lt;a href="http://strangelights.com/blog/archive/2008/03/25/1610.aspx"&gt;Rober Pickering post&lt;/a&gt; about a post about Euler problem 14 ...&lt;br/&gt;
Without changing the algorithm, I ran a simple test to compare F#, ocaml byte code and ocaml native code ... and the result is quite surprising, for me at least!&lt;br/&gt;
The program do a lot of computation on integer (even 64 bits); I remember (no ref) that ocaml is more efficient for floating point operation that for integer. But anyway, just wanted an idea of how to port this code to Ocaml.&lt;br/&gt;
Following is the code in F# as seen on cited post:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
#light
let rec seq_length x n =
    match x with
    | x when x = 0L -&gt; (n + 1)
    | x when x = 1L -&gt; seq_length 0L (n + 1)
    | x when x%2L=0L -&gt;seq_length (x/2L) (n + 1)
    | _ -&gt; seq_length (3L*x + 1L) (n + 1)
let rec loop i imax n =
  let n' = seq_length i 0
  let imax, n = if n' &gt; n then i, n' else imax, n
  if i &lt; 1000000L then loop (i + 1L) imax n else imax
print_any (loop 1L 0L 0)&lt;/code&gt;&lt;/pre&gt;
And here is an Ocaml version:
&lt;pre&gt;&lt;code&gt;
let ( ** ) = Int64.mul
let ( // ) = Int64.div
let ( %% ) = Int64.rem &lt;br/&gt;
let rec seq_length x n =
    match x with
    | 0L -&gt; (n + 1)
    | 1L -&gt; seq_length 0L (n + 1)
    | x when x %% 2L = 0L -&gt; seq_length (x // 2L) (n + 1)
    | _ -&gt; seq_length (Int64.succ (3L ** x)) (n + 1)&lt;br/&gt;
let rec loop i imax n =
  let n' = seq_length i 0 in
  let imax, n = if n' &gt; n then (i, n') else (imax, n) in
  if i &lt; 1000000L then loop (Int64.succ i) imax n else imax
let _ = print_string (Int64.to_string (loop 1L 0L 0))&lt;/code&gt;&lt;/pre&gt;
Surprisingly (for me!), the compiled F# code is much faster:
&lt;ul&gt;
	&lt;li&gt;time mono eul14.exe: 12.979s&lt;/li&gt;
	&lt;li&gt;time ./eul14.byte: 58.145s&lt;/li&gt;
	&lt;li&gt;time ./eul14.native: 30.234s&lt;/li&gt;
&lt;/ul&gt;
I'm not sure why Ocaml seems to be slower for this test. Can it be a GC issue?
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/l9z8Wa4F8TM" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/fsharp/2008/03/30/ocaml-vs-f-for-big-integer-surprising-performance-test.html</feedburner:origLink></entry>
 
 <entry>
   <title>ocaml native code</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/8yCWguzqCUY/ocaml-native-code.html" />
   <updated>2008-03-25T00:00:00+08:00</updated>
   <id>/wp-import/ocaml/2008/03/25/ocaml-native-code</id>
   <content type="html">I was playing with this mini &lt;a href="http://www.ffconsultancy.com/ocaml/ray_tracer/index.html"&gt;raytracer&lt;/a&gt; and modify it to use &lt;a href="http://www.google.com.sg/url?sa=t&amp;amp;ct=res&amp;amp;cd=1&amp;amp;url=http%3A%2F%2Fglcaml.sourceforge.net%2F&amp;amp;ei=oCbpR9nRDJuq6wOx3pjICA&amp;amp;usg=AFQjCNGRADY053g48yJdDifPbYVSpQN2zg&amp;amp;sig2=TU9C-YxbqrfttRWSGP4oMA"&gt;glcaml&lt;/a&gt; instead of glut.&lt;br/&gt;
I was delighted to see how the native code is faster than the byte compiled one ... of course this is expected but after playing for some time with the byte code I was surprise how fast the result came after the first native compilation :)&lt;br/&gt;
(below is google graph; time unit is second)&lt;br/&gt;
&lt;img src="http://spreadsheets.google.com/pub?key=pdBFVv1I_-8M5L6qUUAfGWg&amp;amp;oid=1&amp;amp;output=image" alt="" /&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/8yCWguzqCUY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ocaml/2008/03/25/ocaml-native-code.html</feedburner:origLink></entry>
 
 <entry>
   <title>ocamerl ... no update :(</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/YoNm2E8QCOs/ocamerl-no-update.html" />
   <updated>2008-03-13T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/03/13/ocamerl-no-update</id>
   <content type="html">Quick news about ocamerl:
&lt;ul&gt;
	&lt;li&gt;I changed the build system to ocamlbuild (need ocaml 3.10).&lt;/li&gt;
	&lt;li&gt;... and that's all! can't find time to clean all the mess.&lt;/li&gt;
&lt;/ul&gt;
So anyway, here is the current state of ocamerl:
&lt;ul&gt;
	&lt;li&gt;ocaml can register a hidden erlang node (epmd).&lt;/li&gt;
	&lt;li&gt;ocaml node can respond to ping and keep connection up with erlang node (net_kernel process)&lt;/li&gt;
	&lt;li&gt;erlang can send (some) terms to named ocaml process&lt;/li&gt;
	&lt;li&gt;ocaml can send (some) terms to erlang process if it received the pid in a previous message&lt;/li&gt;
&lt;/ul&gt;
That's all for now! Argh!&lt;br/&gt;
Amongst things I'd like to change:
&lt;ul&gt;
	&lt;li&gt;simplify terms manipulation in ocaml&lt;/li&gt;
	&lt;li&gt;add features (most important initial message from ocaml to erlang)&lt;/li&gt;
	&lt;li&gt;complete redesign of concurrency (using events or JoCaml maybe!)&lt;/li&gt;
	&lt;li&gt;add a minimum of documentation&lt;/li&gt;
&lt;/ul&gt;
I need motivation! In fact I have no project which would need ocaml + erlang ... for now.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/YoNm2E8QCOs" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/03/13/ocamerl-no-update.html</feedburner:origLink></entry>
 
 <entry>
   <title>For who is this blog?</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/ys-TjMKqe7U/for-who-is-this-blog.html" />
   <updated>2008-03-13T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/03/13/for-who-is-this-blog</id>
   <content type="html">I've been writing here some ideas or development status.&lt;br/&gt;
But looks like my readers are more oriented towards code examples or solutions ... so I'll try to be more pragmatic in future.&lt;br/&gt;
Anyway my code is better than my English (at least I hope so!) so that should improve quality of this blog ;)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/ys-TjMKqe7U" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/03/13/for-who-is-this-blog.html</feedburner:origLink></entry>
 
 <entry>
   <title>Control by fuzzy logic</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/VbmtaBOU-yE/control-by-fuzzy-logic.html" />
   <updated>2008-03-13T00:00:00+08:00</updated>
   <id>/wp-import/ocaml/2008/03/13/control-by-fuzzy-logic</id>
   <content type="html">As exercise of Ocaml, I wrote a very very simple library for inference using fuzzy logic.&lt;br/&gt;
There is only the bare minimum ... but it's often enough anyway ;). If someone is interested I can:
&lt;ul&gt;
	&lt;li&gt;write a small doc&lt;/li&gt;
	&lt;li&gt;write a example&lt;/li&gt;
	&lt;li&gt;complete some parts&lt;/li&gt;
&lt;/ul&gt;
This is my first &lt;a href="http://github.com/khigia/ocaml-fuzlog"&gt;project&lt;/a&gt; on &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt;.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/VbmtaBOU-yE" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ocaml/2008/03/13/control-by-fuzzy-logic.html</feedburner:origLink></entry>
 
 <entry>
   <title>Could Erlang and ICE be friends?</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/XEpQheTvk3s/could-erlang-and-ice-be-friends.html" />
   <updated>2008-02-19T00:00:00+08:00</updated>
   <id>/wp-import/ice/2008/02/19/could-erlang-and-ice-be-friends</id>
   <content type="html">How could an Erlang process communicate with an &lt;a href="http://www.zeroc.com/ice.html"&gt;ICE&lt;/a&gt;-based application? The mix seems a bit strange (why would you need ICE when you already have Erlang ;) ) but without entering in details of why we would like to do so, let's consider how can we plug an Erlang sub-system in a ICE application.&lt;br/&gt;
One way to go would be to write a &lt;i&gt;slice2erl&lt;/i&gt; compiler! That's presumably lot of work. This kind of work is being done for OCaml in the &lt;a href="http://oss.wink.com/hydro/"&gt;Hydro project&lt;/a&gt; ... and is on my list of next things to play with.&lt;br/&gt;
Another way to get Erlang talk to ICE application would be via a custom intermediate translator between the Erlang app and the ICE system (using some intermediate language having a complete interface with both Erlang and ICE, like C, Java, or Python); yes, this surely add complexity and slow down the full system, but efficiency of distributed application is more often bound by design than by runtime ;).&lt;br/&gt;
Btw, as far as ease-of-development is concern, I have the same kind of feeling when comparing C++ to Python or ICE to Erlang :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/XEpQheTvk3s" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ice/2008/02/19/could-erlang-and-ice-be-friends.html</feedburner:origLink></entry>
 
 <entry>
   <title>Language typing: no strong preference yet!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/h6_4s8oQg6s/language-typing-no-strong-preference-yet.html" />
   <updated>2008-01-17T00:00:00+08:00</updated>
   <id>/wp-import/general/2008/01/17/language-typing-no-strong-preference-yet</id>
   <content type="html">Having used different kinds of language (C++, python, ruby, ocaml, erlang), I still can't choose what kind of typing I prefer as far as static vs dynamic typing is concerned (I will not discuss the strong vs duck typing).&lt;br/&gt;
I'm not convince that a static type system is a useful "bug avoidance system" (for my kind of development habits at least!). Not that it cannot prevent some bugs, but those are probably the "easy bugs" that would have show-up in unit-tests ... and this is exactly the point: unit-tests are anyway necessary to test the functional aspect, so type kind of bug will be found in either kind of development environment.&lt;br/&gt;
Having written lot of code in python and C++, I sure better love python: I will not repeat here why language like python or ruby are more easy to read, more concise and so on ...&lt;br/&gt;
However in team environment, a type is a first documentation feature! In a clear API, the type information is nearly enough to use the API (most python API documentation define all types of the parameters ...).&lt;br/&gt;
Also with my last experiences with ocaml, I discover that having to define the type oblige to think more about &lt;b&gt;what&lt;/b&gt; is the data. When thinking of the type of a data, you end-up asking you question like: what is it that I want to manipulate? if it should have this and that method, is it an application object? is it a subcomponent of my current object? is it a facet/interface of my object? can I abstract this "thing"? ... all that is a good point in favor of strongly typed language at compile time as it help to concentrate on defining data!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/h6_4s8oQg6s" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2008/01/17/language-typing-no-strong-preference-yet.html</feedburner:origLink></entry>
 
 <entry>
   <title>Pythonize your vim</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/ZMP2mUxt9_s/pythonize-your-vim.html" />
   <updated>2008-01-17T00:00:00+08:00</updated>
   <id>/wp-import/python/2008/01/17/pythonize-your-vim</id>
   <content type="html">Tip I enjoyed today: python in vim, how cool is that!?&lt;br/&gt;
For those who like vim but not the vim script language, try &lt;i&gt;:help python&lt;/i&gt;.&lt;br/&gt;
Example:
&lt;i&gt;:py import vim
:py [vim.current.buffer.append(str(e)) for e in xrange(10)]
&lt;/i&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/ZMP2mUxt9_s" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/python/2008/01/17/pythonize-your-vim.html</feedburner:origLink></entry>
 
 <entry>
   <title>Coming soon: an interesting post about ocamerl</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/k6SYwY4a_eY/coming-soon-an-interesting-post-about-ocamerl.html" />
   <updated>2008-01-08T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/01/08/coming-soon-an-interesting-post-about-ocamerl</id>
   <content type="html">Managed to have some time to play with ocamerl: ocaml node is now able to receive data from erlang node, and also send data to pid on connected nodes.&lt;br/&gt;
I begin to understand what I'm doing, so that I will be able to clean the code and refactor some parts very soon.&lt;br/&gt;
As example, &lt;a href="http://erlocaml.googlecode.com/svn/trunk/lib/ocamerl/ocaml/ex/node_double.ml"&gt;an ocaml process&lt;/a&gt; which multiply integer by 2! wow! What' an interesting example!&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
bash&gt; cd trunk/lib/ocamerl
bash&gt; ./ex/node_double &gt;/dev/null 2&gt;&amp;1 &amp;
bash&gt; erl -setcookie cookie  -sname erl
erl@devhost 1&gt; net_adm:ping(ocaml@devhost).
pong
erl@devhost 2&gt; {bytwo, ocaml@devhost} ! {self(), 8}.
{&lt;0.37.0&gt;,8}
erl@devhost 3&gt;  receive I -&gt; io:format("Got: ~w~n", [I]) after 0 -&gt; ko end.
Got: 16
ok&lt;/code&gt;&lt;/pre&gt;
Note: the ping was optional and the answer seems correct: 8 * 2 = 16!
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/k6SYwY4a_eY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/01/08/coming-soon-an-interesting-post-about-ocamerl.html</feedburner:origLink></entry>
 
 <entry>
   <title>Simple game</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/CaPdysBMohc/simple-game.html" />
   <updated>2008-01-02T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2008/01/02/simple-game</id>
   <content type="html">It's kind of surprising how people can like such a simple game as pong. Isn't it even more odd to find programmer which enjoy their program to play?&lt;br/&gt;
All that to say: ocaml node (using the ocamerl lib of &lt;a href="http://code.google.com/p/erlocaml/"&gt;erlocaml&lt;/a&gt;) can now reply pong to a ping request from erlang node ;) ... and that's all it can do!&lt;br/&gt;
Next step: receive data :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/CaPdysBMohc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2008/01/02/simple-game.html</feedburner:origLink></entry>
 
 <entry>
   <title>ocamerl update: handshake</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/i3Ob-z3LB1Y/ocamerl-update-handshake.html" />
   <updated>2007-12-28T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/12/28/ocamerl-update-handshake</id>
   <content type="html">Code in ocamerl (part of erlocaml) pass the node handshake.  Hopefully nobody will read this code before I clean it up a bit ... because right now it is a furious mess!!!&lt;br/&gt;
I spent some time (arg, that's a lot in fact) on a stupid (as the bug's author) bug. The (simplified) handshake is a follow:
&lt;ul&gt;
	&lt;li&gt;the 2 nodes exchange a challenge which is 4 random bytes interpreted as a Int32;&lt;/li&gt;
	&lt;li&gt;each node computes the MD5 of (their own cookie + challenge);&lt;/li&gt;
	&lt;li&gt;each node compares its result with the digest of the other node.&lt;/li&gt;
&lt;/ul&gt;
My bug was to concatenate the cookie (string) with the raw 4 bytes of the challenge ... where I had to concatenate the cookie with the string representation of the 32 bits long unsigned integer!&lt;br/&gt;
(in fact the handshake is done with 2 challenges: each node send a challenge to the other)&lt;br/&gt;
Anyway, the handshake pass correctly now, and ocaml node can receive the ping control message ... but do not reply yet! after it reply, sure I clean the code!!!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/i3Ob-z3LB1Y" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/12/28/ocamerl-update-handshake.html</feedburner:origLink></entry>
 
 <entry>
   <title>Concurrent behaviours</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/oN0JaF5J28w/concurrent-behaviours.html" />
   <updated>2007-12-22T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/12/22/concurrent-behaviours</id>
   <content type="html">As spotted in this &lt;a href="http://gilesbowkett.blogspot.com/2007/12/erlang-robotics.html"&gt;blog post&lt;/a&gt; using Erlang in robotics seems a pretty good idea to implement robust systems and concurrent behaviours.&lt;br/&gt;
However I do not consider the subsumption architecture (Brooks, 1986) as the best example of action selection architecture for concurrent behaviours. As far as I remember, the subsumption architecture assumes predefined priorities on behaviours (hierarchy), and has a fix set of rules on how some behaviours can subsume others.&lt;br/&gt;
As far as reactive architectures are concerned, IMHO Erlang style of concurrency could be more effectively used on architecture using activation networks (Maes, 1989), or a voting mechanism &lt;i&gt;a la&lt;/i&gt; DAMN (Rosenblatt, 1995), or a pertinence-based selection like Creature (Blumberg, 1997), or whatever architecture which enable a distribution of control.&lt;br/&gt;
But yes, Erlang seems quite a good match to implement autonomous entities (robots or software agents (MAS)).&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/oN0JaF5J28w" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/12/22/concurrent-behaviours.html</feedburner:origLink></entry>
 
 <entry>
   <title>ocamerl</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/3gRyDa6Mt1k/ocamerl.html" />
   <updated>2007-12-16T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/12/16/ocamerl</id>
   <content type="html"> Christmas is coming, and I found a new toy to play with: ocamerl. This is a very simple solution to exchange data between erlang and ocaml. In fact, this is mainly an ocaml implementation of the erlang external binary format (based on &lt;a href="http://groups.google.com/group/erlocaml-discuss/browse_thread/thread/920bc75a60a3e2e5"&gt;this discussion/code&lt;/a&gt;). I just added few tools to make a TCP connection to exchange those data.&lt;br/&gt;
On erlang side, I use 2 processes: the receiver process listen on a TCP port,read data and send it back to any erlang process meant to handle incoming data; the second process is busy transfering all data in its message queue to some TCP server (the ocaml part). On ocaml side, there are a couple a function to transform erlang forms in ocaml entities and vice versa.&lt;br/&gt;
I only wrote a very very simple exemple: an ocaml echo server, which multiply by 2 all integers sent in message (deep search in tuple).&lt;br/&gt;
Erlang side init:&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
1&gt;Receiver = spawn(oe, print_mailbox, []).
2&gt;Sender = oe:messenger(12345, 54321, Receiver).&lt;/code&gt;&lt;/pre&gt;
Ocaml side init:
&lt;pre&gt;&lt;code&gt;
./ex/double -recv 12345 -send 54321&lt;/code&gt;&lt;/pre&gt;
Then, any term sent to from erlang is sent back by ocaml.
&lt;pre&gt;&lt;code&gt;
3&gt; Sender ! {true, 12, {1,2}}.
{true,12,{1,2}}
Sending data: &lt;&lt;131,104,3,100,0,4,116,114,117,101,97,12,104,2,97,1,97,2&gt;&gt;
Received binary: &lt;&lt;131,104,3,100,0,4,116,114,117,101,97,24,104,2,97,2,97,4&gt;&gt;
Converted to term: {true,24,{2,4}}
Received: {true,24,{2,4}}&lt;/code&gt;&lt;/pre&gt;
Funny, isn't it ? :) This is an early stage of course. Code is part of &lt;a href="http://code.google.com/p/erlocaml"&gt;erlocaml project&lt;/a&gt; (in lib/ocamerl). My goal is to write a hidden erlang node in ocaml. Not sure it is useful, but quite certain it is interesting ;)
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/3gRyDa6Mt1k" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/12/16/ocamerl.html</feedburner:origLink></entry>
 
 <entry>
   <title>Hylomorphism and Euler problem 2</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/XW6lJ-LGhVg/hylomorphism-and-euler-problem-2.html" />
   <updated>2007-11-19T00:00:00+08:00</updated>
   <id>/wp-import/ocaml/2007/11/19/hylomorphism-and-euler-problem-2</id>
   <content type="html">In my recent posts I've played with &lt;a href="http://khigia.wordpress.com/2007/11/14/euler-problem-2/"&gt;Euler problem 2&lt;/a&gt; and &lt;a href="http://khigia.wordpress.com/2007/11/11/hylo-again/"&gt;hylomorphism&lt;/a&gt;: here I use the hylomorphism concept to solve the Euler problem 2 using Ocaml :)&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
(* Given a hylomorphism implementation ...*)
let rec hylo_impl step till col inj v s =
    if till s
    then v
    else
        let ns = step s in
        let nv = inj (col s) v in
        hylo_impl step till col inj nv ns
;;
(* ... solving Euler problem 2 is quite easy! *)
let eul2 n =
    hylo_impl
        (fun (n0, n1) -&gt; (n1, n0 + n1))
        (fun (n0, n1) -&gt; n0 &gt; n)
        (fun (n0, n1) -&gt; if n0 mod 2 == 0 then n0 else 0)
        (fun x a -&gt; x + a)
        0
        (1, 1)
;;&lt;/code&gt;&lt;/pre&gt;
This time I tried to add default value with labels notation of Ocaml. But I have a problem with type inference: if the given default function has a type, all function I pass as parameter must have the same type as the default one ... still have to learn a bit more about polymorphism in ocaml I presume ;). The following code may work in some case, but it forces the type of the functions, which is really bad! &lt;strong&gt;Any advice to solve this problem?&lt;/strong&gt;
&lt;pre&gt;&lt;code&gt;
let hylo
        ?(step = fun x -&gt; x + 1)
        ?(till = fun x -&gt; true)
        ?(col = fun x -&gt; x)
        ?(inj = ((fun x a -&gt; x :: a), []))
        s
    =
    let (injf, injv) = inj in
    hylo_impl step till col injf injv s
;;&lt;/code&gt;&lt;/pre&gt; 
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/XW6lJ-LGhVg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/ocaml/2007/11/19/hylomorphism-and-euler-problem-2.html</feedburner:origLink></entry>
 
 <entry>
   <title>Euler problem 2</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/o7uoQ-2-yd4/euler-problem-2.html" />
   <updated>2007-11-14T00:00:00+08:00</updated>
   <id>/wp-import/fsharp/2007/11/14/euler-problem-2</id>
   <content type="html">This &lt;a href="http://blogs.msdn.com/chrsmith/archive/2007/10/26/Project-Euler-in-F_2300_-_2D00_-Problem-2.aspx"&gt;blogpost&lt;/a&gt; present a good F# solution to Euler problem 2. The code make use of infinite sequence. I've written other solutions to this same problem. The first one is a code specialized to solve this problem: it computes the fibonacci sequence while checking the problem conditions and computing the problem answer.
&lt;pre&gt;&lt;code&gt;
#light
let rec fib_filter_fold (n0,n1) filter folder acc m =
    if n0 &lt;= m
    then fib_filter_fold (n1, n0 + n1) filter folder (if filter n0 then (folder acc n0) else acc) m
    else acc
let pb2 m = fib_filter_fold (1,1) (fun x -&gt; x % 2 = 0) (fun acc x -&gt; acc + x) 0 m
printf "euler problem 2 (1000000): %a\n" output_any (pb2 1000000)&lt;/code&gt;&lt;/pre&gt;
I then wrote a second version, trying to make use of Seq functions. Idea is to start with the fibonacci sequence and apply some modification on it to solve the problem. I'm not so happy with the result!
&lt;pre&gt;&lt;code&gt;
let fibs =
    Seq.unfold
        (fun (n0, n1) -&gt; Some(n0, (n1, n0 + n1)))
        (1, 1)
let reach_index s m =
    s
    |&gt; Seq.mapi (fun i x -&gt; (i, x))
    |&gt; Seq.find_index (fun x -&gt; x &gt; m)
let pb2seq n =
    Seq.truncate (reach_index fibs n) fibs
    |&gt; Seq.filter (fun x -&gt; x % 2 = 0)
    |&gt; Seq.fold (fun acc x -&gt; acc + x) 0
printf "euler problem with seq (1000000): %a\n" output_any (pb2seq 1000000)&lt;/code&gt;&lt;/pre&gt;
Why don't I like this? because I have to manipulate the sequence twice, first to find the index of the last element to take into account, and second to compute the problem answer.I would have like a method 'take_while' in Seq to write something in the line of:
&lt;pre&gt;&lt;code&gt;
let pb2_not_compilable n =
    fibs
    |&gt; Seq.take_while (fun x -&gt; x &lt; n)
    |&gt; Seq.filter (fun x -&gt; x % 2 = 0)
    |&gt; Seq.fold (fun acc x -&gt; acc + x) 0&lt;/code&gt;&lt;/pre&gt;
... am I missing something?Btw, how to implement this "take_while" function? I've try, but Seq has a 'hd' function but no 'tail' ... what am I missing here? I'm sure this is possible to implement ...
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/o7uoQ-2-yd4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/fsharp/2007/11/14/euler-problem-2.html</feedburner:origLink></entry>
 
 <entry>
   <title>Hylo again</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/fKJ4dYv-Uuc/hylo-again.html" />
   <updated>2007-11-11T00:00:00+08:00</updated>
   <id>/wp-import/fsharp/2007/11/11/hylo-again</id>
   <content type="html">The &lt;a href="http://khigia.wordpress.com/2007/11/11/morphing-ruby-to-erlang-just-for-fun/"&gt;previous blogpost&lt;/a&gt; implements a hylomorphism in Erlang.&lt;br/&gt;
Following is again the same in F#: but this is part of my exercices to learn F#, and I just begin to learn ... so the code is ... ergh, whatever.&lt;br/&gt;
And I have no idea how to implement default values. Any advice?&lt;br/&gt;
&lt;pre&gt;&lt;code&gt;
#light
open Microsoft.FSharp.Collections.List;
let rec hylo step till col inj v s =
    if till s
    then
        v
    else
        let ns = step s in
        let nv = inj v (col s) in
        hylo step till col inj nv ns;
let fact =
    let step = fun x -&gt; x - 1 in
    let till = fun x -&gt; x &lt;= 1 in
    let col = fun x -&gt; x in
    let inj = fun a x -&gt; a * x in
    hylo step till col inj 1;
let evens n =
    let step = fun x -&gt; x + 2 in
    let till = fun x -&gt; x &gt;= n in
    let col = fun x -&gt; x in
    let inj = fun a x -&gt; x :: a in
    rev (hylo step till col inj [] 0);
let to_bin n =
    let step = fun x -&gt; x / 2 in
    let till = fun x -&gt; x &lt;= 0 in
    let col = fun x -&gt; x % 2 in
    let inj = fun a x -&gt; x :: a in
    hylo step till col inj [] n;
let expand l =
    let rec duplicate c n a =
        if n &gt; 0
        then duplicate c (n - 1) (c::a)
        else a
        in
    let step = fun li -&gt; tl li in
    let till = fun li -&gt; match li with |[] -&gt; true |_ -&gt; false in
    let col = fun li -&gt; match hd(li) with |(c,n) -&gt; duplicate c n [] in
    let inj = fun a x -&gt; (x :: a) in
    rev (hylo step till col inj [] l);
do printf "fact(5)=%a\n" output_any (fact 5);
do printf "evens(10)=%a\n" output_any (evens 10);
do printf "to_bin(10)=%a\n" output_any (to_bin 10);
do printf "expand([(1,2); (4,7)])=%a\n" output_any (expand [(1, 2); (4,7)]); 
&lt;/code&gt;&lt;/pre&gt; 
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/fKJ4dYv-Uuc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/fsharp/2007/11/11/hylo-again.html</feedburner:origLink></entry>
 
 <entry>
   <title>Morphing ruby to erlang just for fun</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/tM4ORSl8Svg/morphing-ruby-to-erlang-just-for-fun.html" />
   <updated>2007-11-11T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/11/11/morphing-ruby-to-erlang-just-for-fun</id>
   <content type="html">&lt;p&gt;Read some introductions to theory of categories (a &lt;a href="http://math.ucr.edu/home/baez/week73.html"&gt;very good introduction &lt;/a&gt;to the theory, or this one &lt;a href="http://reperiendi.wordpress.com/2007/11/03/category-theory-for-the-java-programmer"&gt;more programmer oriented&lt;/a&gt;). As I also stumble upon &lt;a href="http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/1052c289b22c60a5"&gt;this thread&lt;/a&gt;, I discover a new concept: "hylomorphism is a composite of an anamorphism (unfold) and an catamorphism  (fold/inject) &lt;a href="http://tunes.org/wiki/Morphism"&gt;[1]&lt;/a&gt;, &lt;a href="http://www.cs.nott.ac.uk/~cvh/hylos/hylos.pdf"&gt;[2]&lt;/a&gt;", along with a ruby code to implement it in some way (this the googlegroup thread above).&lt;/p&gt;
&lt;p&gt;Just for fun (and be sure to understand it), I translated the code in Erlang. I've used the property list module to implement some kind of default value, but it's not really elegant. Anyway, code is here.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
-module(hylo).
-export([
    % hylomorphism API
    new/1,
    % examples/toys
    evens/1,
    fact/1,
    to_bin/1,
    expand/1
]).
% internal declarations
-record(hylo, {
    do,
    till,
    collecting,
    injecting
}).
% API
new(PL) when is_list(PL) -&amp;gt;
    H = #hylo{
        do = proplists:get_value(
            do,
            PL,
            fun(X) -&amp;gt; X + 1 end
        ),
        till = proplists:get_value(
            till,
            PL,
            fun(X) -&amp;gt; X =:= undefined end
        ),
        collecting = proplists:get_value(
            collecting,
            PL,
            fun(X) -&amp;gt; X end
        ),
        injecting = proplists:get_value(
            injecting,
            PL,
            {   [],
                fun(A,E) -&amp;gt; [E|A] end,
                fun lists:reverse/1
            }
        )
    },
    fun(S) -&amp;gt; eval(H, S, element(1,H#hylo.injecting)) end.
% internal implementation
eval(H, S1, R) -&amp;gt;
    {_, InjF, InjR} = H#hylo.injecting,
    case (H#hylo.till)(S1) of
        false -&amp;gt;
            V = (H#hylo.collecting)(S1),
            S2 = (H#hylo.do)(S1),
            eval(H, S2, InjF(R, V));
        _ -&amp;gt;
            InjR(R)
    end.
% examples
evens(N) -&amp;gt;
    H = new([
        {do, fun(X) -&amp;gt; X + 2 end},
        {till, fun(X) -&amp;gt; X &amp;gt;= N end}
    ]),
    H(0).
fact(N) when N &amp;gt; 0 -&amp;gt;
    H = new([
        {do, fun(X) -&amp;gt; X - 1 end},
        {till, fun(X) -&amp;gt; X =&amp;lt; 1 end},
        {injecting, {1, fun(A,E) -&amp;gt; A * E end, fun(A) -&amp;gt; A end}}
    ]),
    H(N).
to_bin(N) when N &amp;gt; 0 -&amp;gt;
    H = new([
        {do, fun(X) -&amp;gt; X div 2 end},
        {till, fun(X) -&amp;gt; X =&amp;lt; 0 end},
        {collecting, fun(X) -&amp;gt; (X rem 2) end},
        {injecting, {[], fun(A,E) -&amp;gt; [E|A] end, fun(A) -&amp;gt; A end}}
    ]),
    H(N).
expand(L) -&amp;gt;
    H = new([
        {do, fun ([_|T]) -&amp;gt; T; ([]) -&amp;gt; [] end},
        {till, fun ([]) -&amp;gt; true; (_) -&amp;gt; false end},
        {collecting, fun([{C,N}|_]) -&amp;gt; lists:duplicate(N, C) end}
    ]),
    H(L).
-ifdef(EUNIT).
-include_lib("eunit/include/eunit.hrl").
evens_test() -&amp;gt;
    ?assert(evens(10) =:= [0,2,4,6,8]).
fact_test() -&amp;gt;
    ?assert(fact(5) =:= 120).
to_bin_test() -&amp;gt;
    ?assert(to_bin(10) =:= [1,0,1,0]).
expand_test() -&amp;gt;
    ?assert(expand([{$a,2},{$b,3},{$c,4}]) =:= ["aa", "bbb", "cccc"]).
-endif.&lt;/code&gt;&lt;/pre&gt;
&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/tM4ORSl8Svg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/11/11/morphing-ruby-to-erlang-just-for-fun.html</feedburner:origLink></entry>
 
 <entry>
   <title>xkcd draw the time...</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/JUAAUi1G7JY/xkcd-draw-the-time.html" />
   <updated>2007-11-05T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/11/05/xkcd-draw-the-time</id>
   <content type="html">&lt;img src="http://imgs.xkcd.com/comics/future.png" style="width:80%;" alt="Future" /&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/JUAAUi1G7JY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/11/05/xkcd-draw-the-time.html</feedburner:origLink></entry>
 
 <entry>
   <title>Mobile phone keyboard</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/dnMrh9NXBME/mobile-phone-keyboard.html" />
   <updated>2007-10-26T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/10/26/mobile-phone-keyboard</id>
   <content type="html">Was "playing" with keyboard map and layout recently in my Ubuntu 7.10 and realized that mobile phone dedicated to SMS or email have a keyboard's layout following the PC QWERTY keyboard (e.g. Nokia E61i).&lt;br/&gt;
Is there any phone with a Dvorak layout? Shall we assume that phone user already know the PC keyboard and do not want to learn another one?&lt;br/&gt;
But could we assume that the size change imply a new learning of the keyboard usage, and this is good time to change the layout for a more appropriate one?&lt;br/&gt;
Is this all nonsense?&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/dnMrh9NXBME" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/10/26/mobile-phone-keyboard.html</feedburner:origLink></entry>
 
 <entry>
   <title>Erlang walk in AVI file</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/uMH0toKcxKs/erlang-walk-in-avi-file.html" />
   <updated>2007-10-09T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/10/09/erlang-walk-in-avi-file</id>
   <content type="html">Warning: long post ahead ... but mostly code :)&lt;br/&gt;
This post contains absolutely no idea nor thought: it is just a recap of my attempt to read an AVI file format (or RIFF file format, as I do not parse AVI data but only document structure). Let's go directly in code with this simple module header!
&lt;pre&gt;&lt;font size="-1"&gt;
&lt;font color="#2e8b57"&gt;&lt;strong&gt;-module&lt;/strong&gt;&lt;/font&gt;(avir)&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;font color="#2e8b57"&gt;&lt;strong&gt;
-compile&lt;/strong&gt;&lt;/font&gt;([export_all])&lt;font color="#6a5acd"&gt;.&lt;/font&gt;
&lt;font color="#2e8b57"&gt;&lt;strong&gt;-include&lt;/strong&gt;&lt;/font&gt;&lt;font color="#6a5acd"&gt;_&lt;/font&gt;lib(&lt;font color="#ff00ff"&gt;"kernel/include/file.hrl"&lt;/font&gt;)&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;br/&gt;
dbg(Level, Template, Args) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    Indent &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; &lt;font color="#008b8b"&gt;lists&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;flatten&lt;/font&gt;(&lt;font color="#008b8b"&gt;lists&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;duplicate&lt;/font&gt;(Level, &lt;font color="#ff00ff"&gt;"  "&lt;/font&gt;)),
    &lt;font color="#008b8b"&gt;io&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;format&lt;/font&gt;(Indent &lt;font color="#a52a2a"&gt;&lt;strong&gt;++&lt;/strong&gt;&lt;/font&gt; Template, Args)&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;br/&gt;
go() &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    go(&lt;font color="#ff00ff"&gt;"test.avi"&lt;/font&gt;)&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;br/&gt;
go(Filename) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    {ok, #file_info{&lt;font color="#008b8b"&gt;size&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt;Size}} &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; &lt;font color="#008b8b"&gt;file&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;read&lt;/font&gt;&lt;font color="#6a5acd"&gt;_&lt;/font&gt;&lt;font color="#008b8b"&gt;file&lt;/font&gt;&lt;font color="#6a5acd"&gt;_&lt;/font&gt;&lt;font color="#008b8b"&gt;info&lt;/font&gt;(Filename),
    {ok, IODev} &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; &lt;font color="#008b8b"&gt;file&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;open&lt;/font&gt;(Filename, [read, &lt;font color="#008b8b"&gt;binary&lt;/font&gt;]),
    {ok, Parts} &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; walk_data(&lt;font color="#ff00ff"&gt;0&lt;/font&gt;, [], IODev, &lt;font color="#ff00ff"&gt;0&lt;/font&gt;, Size)&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
So, &lt;code&gt;dbg&lt;/code&gt; is a crap function to print debug message ... yeah, the old fashion way, it's so simple for just a post! &lt;code&gt;go&lt;/code&gt; is the main entry point and call the 'real' code: the approach is to call the &lt;code&gt;walk_data&lt;/code&gt; function which will build and return a list of AVI structures (first parameter will be level of nesting, used for printing comment with a meaningful indentation, and second one is an accumulator for recursion to come).&lt;br/&gt;
I mainly use this &lt;a href="http://www.alexander-noe.com/video/documentation/avi.pdf"&gt;short document&lt;/a&gt;: AVI is a (nested) sequence of two kind of structure, either LIST or CHUNK. More precisely, first come a mandatory RIFF-AVI LIST then multiple (and optional) RIFF-AVIX kind of LIST. Let's walk those structures:
&lt;pre&gt;&lt;font size="-1"&gt;
walk_data(Level, Parts, File, From, To) &lt;font color="#a52a2a"&gt;&lt;strong&gt;when&lt;/strong&gt;&lt;/font&gt; From &lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt; To &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;case&lt;/strong&gt;&lt;/font&gt; chunk_or_list(File, From) &lt;font color="#a52a2a"&gt;&lt;strong&gt;of&lt;/strong&gt;&lt;/font&gt;
        avichunk &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            {ok, Part, NextPos} &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; walk_chunk(Level, File, From, To),
            walk_data(Level, [Part|Parts], File, NextPos, To);
        avilist &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            {ok, Part, NextPos} &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; walk_list(Level, File, From, To),
            walk_data(Level, [Part|Parts], File, NextPos, To);
        Error &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            {error, &lt;font color="#ff00ff"&gt;"maybe unexpected EOF"&lt;/font&gt;, Error}
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/font&gt;;
walk_data(&lt;font color="#6a5acd"&gt;_&lt;/font&gt;Level, Parts, &lt;font color="#6a5acd"&gt;_&lt;/font&gt;File, &lt;font color="#6a5acd"&gt;_&lt;/font&gt;From, &lt;font color="#6a5acd"&gt;_&lt;/font&gt;To) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    {ok, &lt;font color="#008b8b"&gt;lists&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;reverse&lt;/font&gt;(Parts)}&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;br/&gt;
chunk_or_list(File, Pos) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;case&lt;/strong&gt;&lt;/font&gt; &lt;font color="#008b8b"&gt;file&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;pread&lt;/font&gt;(File, Pos, &lt;font color="#ff00ff"&gt;4&lt;/font&gt;) &lt;font color="#a52a2a"&gt;&lt;strong&gt;of&lt;/strong&gt;&lt;/font&gt;
        {ok, &lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;lt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color="#ff00ff"&gt;"RIFF"&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            avilist;
        {ok, &lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;lt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color="#ff00ff"&gt;"LIST"&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            avilist;
        {ok, &lt;font color="#6a5acd"&gt;_&lt;/font&gt;FourCC} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            avichunk;
        eof &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            eof
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/font&gt;&lt;font color="#6a5acd"&gt;.&lt;/font&gt;
&lt;/font&gt;&lt;/pre&gt;
Walk is straightforward, from position &lt;code&gt;From&lt;/code&gt; to &lt;code&gt;To&lt;/code&gt;, accumulating result in reverse order (I love this &lt;code&gt;[head|tail]&lt;/code&gt; list notation ... was Prolog the first to use it?). &lt;code&gt;chunk_or_list&lt;/code&gt; read few bytes (the &lt;code&gt;FourCC&lt;/code&gt; header) to guess the kind of the next structure (CHUNK or LIST) in file; this structure is loaded, and walk continue.
&lt;pre&gt;&lt;font size="-1"&gt;
walk_list(Level, File, From, To) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;case&lt;/strong&gt;&lt;/font&gt; read_list_header(File, From) &lt;font color="#a52a2a"&gt;&lt;strong&gt;of&lt;/strong&gt;&lt;/font&gt;
        {ok, AviList&lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt;{avilist, List, FourCC, DataPos, DataSize}, NextPos} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            dbg(Level, &lt;font color="#ff00ff"&gt;"read list header (pos=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt;, next=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt;): List=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt; FourCC=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;"&lt;/font&gt;, [From, NextPos, List, FourCC]),
            {ok, SubPart} &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;strong&gt;case&lt;/strong&gt;&lt;/font&gt; FourCC &lt;font color="#a52a2a"&gt;&lt;strong&gt;of&lt;/strong&gt;&lt;/font&gt;
                &lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;lt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color="#ff00ff"&gt;"movi"&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
                    dbg(Level, &lt;font color="#ff00ff"&gt;"... skipping list FourCC=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt;...&lt;/font&gt;&lt;font color="#6a5acd"&gt;~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;"&lt;/font&gt;, [FourCC]),
                    {ok, []};
                &lt;font color="#6a5acd"&gt;_&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
                    walk_data(Level &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;1&lt;/font&gt;, [], File, DataPos, DataPos &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; DataSize)
            &lt;font color="#a52a2a"&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/font&gt;,
            {ok, {AviList, SubPart}, NextPos};
        eof &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            dbg(Level, &lt;font color="#ff00ff"&gt;"end of file&lt;/font&gt;&lt;font color="#6a5acd"&gt;~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;"&lt;/font&gt;, []),
            eof
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/font&gt;&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;br/&gt;
read_list_header(File, Pos) &lt;font color="#a52a2a"&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/font&gt;
    &lt;font color="#a52a2a"&gt;&lt;b&gt;case&lt;/b&gt;&lt;/font&gt; &lt;font color="#008b8b"&gt;file&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;pread&lt;/font&gt;(File, [{Pos, &lt;font color="#ff00ff"&gt;4&lt;/font&gt;}, {Pos &lt;font color="#a52a2a"&gt;&lt;b&gt;+&lt;/b&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;4&lt;/font&gt;, &lt;font color="#ff00ff"&gt;4&lt;/font&gt;}, {Pos &lt;font color="#a52a2a"&gt;&lt;b&gt;+&lt;/b&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;8&lt;/font&gt;, &lt;font color="#ff00ff"&gt;4&lt;/font&gt;}]) &lt;font color="#a52a2a"&gt;&lt;b&gt;of&lt;/b&gt;&lt;/font&gt;
        {ok, [List, &lt;font color="#a52a2a"&gt;&lt;b&gt;&amp;lt;&amp;lt;&lt;/b&gt;&lt;/font&gt;&lt;font color="#008b8b"&gt;Size&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#ff00ff"&gt;4&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;b&gt;/&lt;/b&gt;&lt;/font&gt;little-unsigned&lt;font color="#a52a2a"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#008b8b"&gt;integer&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt;&lt;font color="#008b8b"&gt;unit&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#ff00ff"&gt;8&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;b&gt;&amp;gt;&amp;gt;&lt;/b&gt;&lt;/font&gt;, FourCC]} &lt;font color="#a52a2a"&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/font&gt;
            {ok, {avilist, List, FourCC, Pos &lt;font color="#a52a2a"&gt;&lt;b&gt;+&lt;/b&gt;&lt;/font&gt; 12, Size &lt;font color="#a52a2a"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;4&lt;/font&gt;}, Pos &lt;font color="#a52a2a"&gt;&lt;b&gt;+&lt;/b&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;8&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;b&gt;+&lt;/b&gt;&lt;/font&gt; Size};
        {ok, [eof, eof, eof]} &lt;font color="#a52a2a"&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/font&gt;
            eof;
        &lt;font color="#6a5acd"&gt;_&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/font&gt;
            {error, &lt;font color="#ff00ff"&gt;&amp;quot;no list header to read, but not empty data&lt;/font&gt;&lt;font color="#6a5acd"&gt;~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;&amp;quot;&lt;/font&gt;}
    &lt;font color="#a52a2a"&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;&lt;font color="#6a5acd"&gt;.&lt;/font&gt;
&lt;/font&gt;&lt;/pre&gt;
To walk a LIST, read the header (remember that the FourCC field length is part of the data size ...), read the nested data (this re-use the walk_data), and return the LIST representation: a 2-tuple with first the header (could be a record) and then a list of sub parts. There is a useless test to not walk the real data because my test file is kind of big. Walking the CHUNK is quite the same.
&lt;pre&gt;&lt;font size="-1"&gt;
walk_chunk(Level, File, From, To) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;case&lt;/strong&gt;&lt;/font&gt; read_chunk_header(File, From) &lt;font color="#a52a2a"&gt;&lt;strong&gt;of&lt;/strong&gt;&lt;/font&gt;
        {ok, AviChunk&lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt;{avichunk, FourCC, DataPos, DataSize}, NextPos} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            &lt;font color="#0000ff"&gt;%FourCC = &amp;lt;&amp;lt;_StreamNumber:2/binary, _DataType:2/binary&amp;gt;&amp;gt;},&lt;/font&gt;
            dbg(Level,  &lt;font color="#ff00ff"&gt;"read chunk header (pos=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt;, next=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt;): FourCC=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p&lt;/font&gt;&lt;font color="#ff00ff"&gt; DataSize=&lt;/font&gt;&lt;font color="#6a5acd"&gt;~p~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;"&lt;/font&gt;, [From, NextPos, FourCC, DataSize]),
            chunk_spy(FourCC, File, DataPos, DataSize),
            {ok, AviChunk, NextPos};
        eof &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            dbg(Level, &lt;font color="#ff00ff"&gt;"end of file&lt;/font&gt;&lt;font color="#6a5acd"&gt;~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;"&lt;/font&gt;, []),
            eof
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/font&gt;&lt;font color="#6a5acd"&gt;.&lt;/font&gt;&lt;br/&gt;
read_chunk_header(File, Pos) &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;case&lt;/strong&gt;&lt;/font&gt; &lt;font color="#008b8b"&gt;file&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#008b8b"&gt;pread&lt;/font&gt;(File, [{Pos, &lt;font color="#ff00ff"&gt;4&lt;/font&gt;}, {Pos &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;4&lt;/font&gt;, &lt;font color="#ff00ff"&gt;4&lt;/font&gt;}]) &lt;font color="#a52a2a"&gt;&lt;strong&gt;of&lt;/strong&gt;&lt;/font&gt;
        {ok, [FourCC, &lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;lt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color="#008b8b"&gt;Size&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#ff00ff"&gt;4&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;/&lt;/strong&gt;&lt;/font&gt;little-unsigned&lt;font color="#a52a2a"&gt;&lt;strong&gt;-&lt;/strong&gt;&lt;/font&gt;&lt;font color="#008b8b"&gt;integer&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;-&lt;/strong&gt;&lt;/font&gt;&lt;font color="#008b8b"&gt;unit&lt;/font&gt;&lt;font color="#6a5acd"&gt;:&lt;/font&gt;&lt;font color="#ff00ff"&gt;8&lt;/font&gt;&lt;font color="#a52a2a"&gt;&lt;strong&gt;&amp;gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;]} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            NextPos &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; Pos &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;8&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; Size,
            PaddedNextPos &lt;font color="#a52a2a"&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;/font&gt; NextPos &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; (NextPos &lt;font color="#a52a2a"&gt;&lt;strong&gt;rem&lt;/strong&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;2&lt;/font&gt;),
            {ok, {avichunk, FourCC, Pos &lt;font color="#a52a2a"&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;8&lt;/font&gt;, Size}, PaddedNextPos};
        {ok, [eof, eof]} &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            eof;
        &lt;font color="#6a5acd"&gt;_&lt;/font&gt; &lt;font color="#a52a2a"&gt;&lt;strong&gt;-&amp;gt;&lt;/strong&gt;&lt;/font&gt;
            {error, &lt;font color="#ff00ff"&gt;"no chunk header to read, but not empty data&lt;/font&gt;&lt;font color="#6a5acd"&gt;~n&lt;/font&gt;&lt;font color="#ff00ff"&gt;"&lt;/font&gt;}
    &lt;font color="#a52a2a"&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/font&gt;&lt;font color="#6a5acd"&gt;.&lt;/font&gt;
&lt;/font&gt;&lt;/pre&gt;
Similar to LIST, without nested data. Also, this went wrong at the first attempt: I found in &lt;a href="http://msdn2.microsoft.com/en-us/library/ms779636.aspx"&gt;this page&lt;/a&gt; that CHUNK data is padded to word boundary (grr).&lt;br/&gt;
But that's all it take to read a well formated RIFF file. And for those wondering about the &lt;code&gt;chunk_spy&lt;/code&gt; function, continue to read this blog :).&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/uMH0toKcxKs" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/10/09/erlang-walk-in-avi-file.html</feedburner:origLink></entry>
 
 <entry>
   <title>Erlang/OTP installation from sources</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/XHVVQmz_Z9c/erlangotp-installation-from-sources.html" />
   <updated>2007-09-26T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/09/26/erlangotp-installation-from-sources</id>
   <content type="html">I'm probably missing something in Erlang/OTP installation from sources ... my goal is to install multiple version of OTP in user space.&lt;br/&gt;
Here is one way to do it:
&lt;ol&gt;
	&lt;li&gt; remove any symlink if needed
&lt;code&gt;rm /home/khigia/local/lib/erlang&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;apply the "normal" quick install steps for the new OTP version, let say otp-R11B5
&lt;code&gt;cd /home/khigia/apps/otp-src-R11B5; ./configure --prefix=/home/khigia/local ; make; make install&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;modify the install to be version specific
&lt;code&gt;mv /home/khigia/local/lib/erlang /home/khigia/local/lib/otp-R11B5
ln -s /home/khigia/local/lib/otp-R11B5 /home/khigia/local/lib/erlang&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
Changing the symlink enable to switch Erlang/OTP version. There must be an easiest way ... how?&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/XHVVQmz_Z9c" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/09/26/erlangotp-installation-from-sources.html</feedburner:origLink></entry>
 
 <entry>
   <title>Different DBMS</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/YhiAx7ulQ5E/different-dbms.html" />
   <updated>2007-09-07T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/09/07/different-dbms</id>
   <content type="html">It's common knowledge that DBMS is a very important part of a fast scalable distributed systems as far as performance is concerned. But I often tend to forget it and blindly rely on well known relational DBMS. Recently I stumble upon the following other DBMS/discussions and the last one really opened my eyes:
&lt;ul&gt;
	&lt;li&gt;The Erlang/OTP come with &lt;a href="http://www.erlang.org/doc/apps/mnesia/index.html"&gt;mnesia&lt;/a&gt; allowing transaction on distributed DB. However it has been argue (note: this need some reference...) that distributed mnesia cannot scale (it needs some agreement between all nodes for transaction). For huge distributed system (or nodes on low network) the application has to maintain data consistency without relying on transaction. &lt;a href="http://en.wikipedia.org/wiki/Berkeley_DB"&gt;Berkeley DB&lt;/a&gt; seems to be the preferred way to go for this, but as I understand it, it is not a DBMS which manage distribution but a tool to help you to do so.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://couchdb.org/CouchDB/CouchDBWeb.nsf/Home?OpenForm"&gt;CouchDB&lt;/a&gt; is one DBMS trying to handle the distribution of DB.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Also I just discover the terminology column-oriented DBMS through this (too?) simple &lt;a href="http://en.wikipedia.org/wiki/Column-oriented_DBMS"&gt;wikipedia article&lt;/a&gt;. Being used to R statistics system helped me to (try to) understand what it really is. At least I better understand why Google developed BigTable and I have to &lt;a href="http://labs.google.com/papers/bigtable.html"&gt;read&lt;/a&gt; or &lt;a href="http://video.google.com/videoplay?docid=7278544055668715642"&gt;listen&lt;/a&gt; more about it ...&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/YhiAx7ulQ5E" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/09/07/different-dbms.html</feedburner:origLink></entry>
 
 <entry>
   <title>Recommending popular items</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/FOHO0gueJNE/recommending-popular-items.html" />
   <updated>2007-09-06T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/09/06/recommending-popular-items</id>
   <content type="html">The prediction module using Slope-One algorithm can compute popular items.&lt;br/&gt;
In this implementation, popular items are not only the most frequent items. Each user's ratings defines some kind of relative order of a subset of items. The prediction module compute some kind of global order for all items by merging all "user subset's orders". This is actually using Slope-One algorithm for a user which would rate all items with same score.&lt;br/&gt;
Popular items recommendation is useful for new user!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/FOHO0gueJNE" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/09/06/recommending-popular-items.html</feedburner:origLink></entry>
 
 <entry>
   <title>Screenshot: adviserl services</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/HJcLtPsODSY/screenshot-adviserl-services.html" />
   <updated>2007-08-31T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/08/31/screenshot-adviserl-services</id>
   <content type="html">&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/HJcLtPsODSY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/08/31/screenshot-adviserl-services.html</feedburner:origLink></entry>
 
 <entry>
   <title>Screenshot: adviserl</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/wlSTcf5tq4k/screenshot-adviserl.html" />
   <updated>2007-08-31T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/08/31/screenshot-adviserl</id>
   <content type="html">&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/wlSTcf5tq4k" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/08/31/screenshot-adviserl.html</feedburner:origLink></entry>
 
 <entry>
   <title>One more service for adviserl: an HTTP API</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Ca6nF1fTqG0/one-more-service-for-adviserl-an-http-api.html" />
   <updated>2007-08-31T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/08/31/one-more-service-for-adviserl-an-http-api</id>
   <content type="html">Did I say adviserl need doc and testing ... well ... I did implemented something else: a (too) simple HTTP API based on inets. It enable rating of items and retrieving recommendations. Hopefully it will also display few info about state of adviserl application. If set in config file, adviserl will start inets at startup.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Ca6nF1fTqG0" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/08/31/one-more-service-for-adviserl-an-http-api.html</feedburner:origLink></entry>
 
 <entry>
   <title>mnesia enter in the playground</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/iCaCl2XoL5E/mnesia-enter-in-the-playground.html" />
   <updated>2007-08-23T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/08/23/mnesia-enter-in-the-playground</id>
   <content type="html">adviserl is now version 0.2 thanks to its new default backend: Mnesia.&lt;br/&gt;
&lt;strong&gt;Mnesia&lt;/strong&gt;&lt;br/&gt;
All 4 data services (sources, items, ratings and predictions) can now store everything into Mnesia tables, which help to (let's hope ...) ensure consistency. Using Mnesia will also ease to distribute the application later.&lt;br/&gt;
The main difficulty was the backup of adviserl data because all services are independent. So adviserl only provides tools (&lt;code&gt;adv_mnesia:backup/0&lt;/code&gt;, &lt;code&gt;adv_util:save_files/0&lt;/code&gt;) and the user of adviserl need to know want he want to backup and when (no logic is implemented to backup or restore data). There is no function to restore a backup when adviserl is running, but for a shortcoming, it is easy to stop and restart adviserl.&lt;br/&gt;
For now, adviserl start mnesia if needed, but cannot stop mnesia when adviserl stop. Still wondering if mnesia could/should be an included application (using &lt;code&gt;mnesia_sup&lt;/code&gt; module).&lt;br/&gt;
&lt;strong&gt;API changes
&lt;/strong&gt;&lt;br/&gt;
The main interface has change a little bit to facilitate the use of ID or key to identify items and sources. By default, 'keys' are used to identify sources and items (&lt;code&gt;adviserl:rate/3,4&lt;/code&gt;). New functions enable to directly use ID (&lt;code&gt;adviserl:rate_id/3,4&lt;/code&gt;).&lt;br/&gt;
Also new functions enable to add rating asynchronously (&lt;code&gt;adviserl:async_rate/3,4&lt;/code&gt; and &lt;code&gt;adviserl:async_rate_id/3,4&lt;/code&gt;), meaning that recommendation will not use those ratings until specified (&lt;code&gt;adv_predictions:init/0&lt;/code&gt;): this enable to quickly add a lot of ratings (without expensive update of recommendation data), then purposely trigger a re-initialization of recommendation data.&lt;br/&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br/&gt;
That's all for now.&lt;br/&gt;
I hope I can work on using multiple prediction algorithms, but it may be better to first implement some regression tests and write a minimal documentation ;)&lt;br/&gt;
I'm looking forward to play with recommender algorithms :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/iCaCl2XoL5E" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/08/23/mnesia-enter-in-the-playground.html</feedburner:origLink></entry>
 
 <entry>
   <title>advance backward?</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/2w1RPpBjosg/advance-backward.html" />
   <updated>2007-08-03T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/08/03/advance-backward</id>
   <content type="html">I added a "welcoming bug" feature in &lt;a href="http://code.google.com/p/adviserl"&gt;adviserl&lt;/a&gt;: a simple save_files/0 function to backup the recommender data in a persistent manner.&lt;br/&gt;
That was quick to write, and I really need it now that I begin to look at a lot of data. But it's the wrong way to do it: I need to synchronize the multiple servers before to make or restore the backup. Still wondering if I should have done that in a branch ...&lt;br/&gt;
Anyway, it's here, and it works: if the application anvironment define few files where to save data, those files will be read and written when application start or stop respectively (you can use load_files/0 or save_files/0 whenever you want, but be careful that servers should not process anything else at the same time to avoid inconsistent state).&lt;br/&gt;
Mnesia backend is becoming urgent now ... it's the next point on the &lt;a href="http://code.google.com/p/adviserl/wiki/Roadmap"&gt;roadmap&lt;/a&gt; :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/2w1RPpBjosg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/08/03/advance-backward.html</feedburner:origLink></entry>
 
 <entry>
   <title>Sieve again</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Ai_ZolCB2bg/sieve-again.html" />
   <updated>2007-07-27T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/07/27/sieve-again</id>
   <content type="html">I didn't known this was a so popular problem when I coded &lt;a href="http://khigia.wordpress.com/2007/05/07/44/"&gt;a sieve&lt;/a&gt; of Eratosthene using stream design from SICP.&lt;br/&gt;
In fact, I saw &lt;a href="http://video.google.com/videoplay?docid=810232012617965344"&gt;this video&lt;/a&gt; about NewSqueak which present an example of a concurrent algorithm of the sieve, and in &lt;a href="http://groups.google.de/group/comp.os.plan9/browse_thread/thread/951130abcfcf506e/8c4267a634a0524b?lnk=raot"&gt;this related discussion&lt;/a&gt; on plan9 group I also found &lt;a href="http://video.google.com/videoplay?docid=810232012617965344"&gt;an Haskell implementation&lt;/a&gt; (more related to the stream design than to the concurrent design IMHO). I also had a look at &lt;a href="http://swtch.com/libtask/"&gt;libtask&lt;/a&gt; which offer a C version of the concurrent sieve.&lt;br/&gt;
That's already a lot, so one more shouldn't be useful ... but I like this example, and thus here is &lt;a href="http://paste.lisp.org/display/45190"&gt;my Erlang implementation&lt;/a&gt; using a spawn for each prime in the sieve.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Ai_ZolCB2bg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/07/27/sieve-again.html</feedburner:origLink></entry>
 
 <entry>
   <title>delicious adviserl</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Jt46TiRRJko/delicious-adviserl.html" />
   <updated>2007-07-21T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/07/21/delicious-adviserl</id>
   <content type="html">I (began to) wrote a &lt;a href="http://del.icio.us/"&gt;delicious&lt;/a&gt; API to implement a toy example for &lt;a href="http://code.google.com/p/adviserl/"&gt;adviserl&lt;/a&gt; (thus the &lt;a href="http://adviserl.googlecode.com/svn/trunk/lib/adviserl/examples/delicious/"&gt;code is here&lt;/a&gt;). More about the toy example in next blog post.&lt;br/&gt;
Haven't found anywhere a delicious API library for Erlang ... but haven't really look for it because I wanted to avoid dependency. So I wrote one, organised in 2 parts.
&lt;ul&gt;
	&lt;li&gt; The first part (&lt;code&gt;deli_api&lt;/code&gt;) is able to:
&lt;ul&gt;
	&lt;li&gt; connect to the delicious server and retrieve data (posts) using inets http client;&lt;/li&gt;
	&lt;li&gt; convert those data (posts) in Erlang terms using xmerl (discard XML as different delicious API (rss, api, ...) have different format of the same data);&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
	&lt;li&gt; The second part is a gen_server (&lt;code&gt;deli_posts&lt;/code&gt;) which accept those requests:
&lt;ul&gt;
	&lt;li&gt; &lt;code&gt;{login, User, Password}&lt;/code&gt;, return &lt;code&gt;ok&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt; &lt;code&gt;logout&lt;/code&gt;, return &lt;code&gt;ok&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt; &lt;code&gt;{get_posts, User, [Option]}&lt;/code&gt; with &lt;code&gt;Option=no_update&lt;/code&gt;, return &lt;code&gt;{ok, [Post], archive|uptodate}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
The server will maintain a local cache (a DETS file) and download from delicious server only if needed and requested. The login is only used to retrieve data from delicious server: data put in cache can always be accessed without password.&lt;br/&gt;
I may like to use this API in order to write a plugin for &lt;a href="http://sharedcopy.com/"&gt;SharedCopy&lt;/a&gt;: any shared URL could be automatically posted in delicious (seems easy with &lt;a href="http://yaws.hyber.org/"&gt;Yaws&lt;/a&gt; but I need a web hosting for that).&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Jt46TiRRJko" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/07/21/delicious-adviserl.html</feedburner:origLink></entry>
 
 <entry>
   <title>Storing data into adviserl</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/yFxeUHj9pRk/storing-data-into-adviserl.html" />
   <updated>2007-07-21T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/07/21/storing-data-into-adviserl</id>
   <content type="html">The recommender system &lt;a href="http://code.google.com/p/adviserl/"&gt;adviserl&lt;/a&gt; manage all data (item and user, or source) through identifiers.&lt;br/&gt;
Keeping those identifiers opaque for the whole system is possible, but as many prediction algorithms use integer identifiers (for matrix operations), adviserl provides an API in input of the system to generate integer ID if needed. Thus all identifiers in adviserl are integers, with an automatic conversion if needed.
&lt;code&gt;erl&amp;gt; rate(5, 1, {3,no_data}). # user 5 rate item 1 with score 3 (no rating data)
erl&amp;gt; rate("bill", "microsoft", {5, no_data}). # user "bill" rate item "microsoft" ...
erl&amp;gt; adv_items:id_from_key("microsoft").
2 # item "microsoft" got ID 2
erl&amp;gt; adv_source:id_from_key("bill").
1 # source "bill" got ID 1
&lt;/code&gt;&lt;br/&gt;
The API is also usefull to keep data about items or sources, which open the possibility to content-based recommendation algorithms. For this, it's enough to call the item/source API before to set related ratings. Any item/source has an integer ID, a external key (any Erlang term), and a data term (a property list in the following example).
&lt;code&gt;erl&amp;gt; adv_items:insert_new("linux", [{tags, ["oss", "os"]}]).
{true,3} # bool if inserted or existing, integer is ID
erl&amp;gt; adv_items:object_from_id(3).
{3,"linux",[{tags,["oss","os"]}]} # {ID, Key, Data}
erl&amp;gt; adviserl:rate("linus", "linux", {6,no_data}).&lt;/code&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/yFxeUHj9pRk" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/07/21/storing-data-into-adviserl.html</feedburner:origLink></entry>
 
 <entry>
   <title>Advises on delicious tags</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/gbsqGRLzHHU/advises-on-delicious-tags.html" />
   <updated>2007-07-21T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/07/21/advises-on-delicious-tags</id>
   <content type="html">Because CF need data to learn, small examples to illustrate &lt;a href="http://code.google.com/p/adviserl/"&gt;adviserl&lt;/a&gt; are not easy to find. And thus the first "real" example is already a mis-use of adviserl: it uses the CF algorithm as an IR tool!&lt;br/&gt;
Anyway, here we go, I created a tag recommender with my delicious bookmarks (this is not new, delicious already display related tags, but this is just an application example toy).&lt;br/&gt;
This is done by considering each bookmark as a source (a user) and each tag as an item: each time a tag is associated with a bookmark, this is translated as "the bookmark rate the tag with a score of 1". The complete code is this:
&lt;code&gt;application:start(adviserl),&lt;/code&gt;
&lt;code&gt;{ok, DeliciousPID} = deli_posts:start_link(),&lt;/code&gt;
&lt;code&gt;gen_server:call(DeliciousPID, {login, User, Password}),&lt;/code&gt;
&lt;code&gt;{ok, Posts, _Status} = gen_server:call(DeliciousPID, {get_posts, User, Options}, infinity),&lt;/code&gt;
&lt;code&gt;io:format("Loading posts", []),&lt;/code&gt;
&lt;code&gt;lists:foreach(&lt;/code&gt;
&lt;code&gt;  fun(#delipost{href=HRef,tags=Tags}) -&amp;gt;&lt;/code&gt;
&lt;code&gt;  io:format(".", []),&lt;/code&gt;
&lt;code&gt;  lists:foreach(&lt;/code&gt;
&lt;code&gt;  fun(Tag) -&amp;gt; adviserl:rate(HRef,Tag,{1,no_data}) end,&lt;/code&gt;
&lt;code&gt;  Tags&lt;/code&gt;
&lt;code&gt;  )&lt;/code&gt;
&lt;code&gt;  end,&lt;/code&gt;
&lt;code&gt;  Posts&lt;/code&gt;
&lt;code&gt;),&lt;/code&gt;
&lt;code&gt;io:format("~n", []).&lt;/code&gt;
Getting a recommendation for few keywords is then:
&lt;code&gt;Keywords = ["erlang", "concurrency"],
KeywordIDs = lists:map(fun(K) -&amp;gt; adv_items:id_from_key(K) end, Keywords),
Ratings = lists:map(fun(ID) -&amp;gt; {ID, 1} end, IDs),
Rec0 = adviserl:recommend_all(Ratings),
lists:map(fun({ID,_}) -&amp;gt; {ok,K} = adv_items:key_from_id(ID), K end, Rec0).&lt;/code&gt;
(lot of this code is about format and conversion, hopefully it will be done in next API release).&lt;br/&gt;
This delicious example toy can be run by keywords.sh in &lt;a href="http://adviserl.googlecode.com/svn/trunk/lib/adviserl/examples/delicious/"&gt;delicious example folder&lt;/a&gt;.&lt;br/&gt;
Yeah, I know, we can do the same more easily with few statistics (and &lt;a href="http://www.r-project.org/"&gt;R&lt;/a&gt;) and no CF ... but (1) I needed a small example and (2) this could be extended to use different user accounts.&lt;br/&gt;
Hey! I should try to use &lt;a href="http://www.citeulike.org/"&gt;citeUlike&lt;/a&gt; instead of delicious for the next example!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/gbsqGRLzHHU" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/07/21/advises-on-delicious-tags.html</feedburner:origLink></entry>
 
 <entry>
   <title>adviserl got a gen_server API</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/l5W9pEZflX8/adviserl-got-a-gen_server-api.html" />
   <updated>2007-07-18T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/07/18/adviserl-got-a-gen_server-api</id>
   <content type="html">Until now, to access a remote node running &lt;a href="http://code.google.com/p/adviserl"&gt;adviserl,&lt;/a&gt; you could use the native Erlang RPC:
&lt;code&gt;erlang&amp;gt; rpc:call(adviserl_node@localhost, adviserl, rate, [1, 2, {3,nodata}]).&lt;/code&gt;&lt;br/&gt;
I added a gen_server API to do exactly the same thing:
&lt;code&gt;erlang&amp;gt; gen_server:call({adv_api, adviserl_node@localhost}, {rate, 1, 2, {3,nodata}}).&lt;/code&gt;&lt;br/&gt;
This is not simpler, but not more complicated either, and hopefully this will be more flexible when coming to distribution (the API may then become a global process).&lt;br/&gt;
I also added a bunch of shell script to start, stop, rate, or run prediction from command line. The start-stop script (adv.sh) is quite usefull, while the others are convenient when debugging. Those scripts have yet to be documented :( but are more or less straightforward and have a minimum  help message when bad options or bad arguments are given.
&lt;code&gt;shell&amp;gt; ./bin/adv.sh start
shell&amp;gt; ./bin/adv-rate.sh 1 2 2 # user 1 rate item 2 with score 2
shell&amp;gt; ./bin/adv-rate.sh 1 3 3 # ...
shell&amp;gt; ./bin/adv-rate.sh 2 3 3
shell&amp;gt; ./bin/adv-rate.sh 2 4 4
shell&amp;gt; ./bin/adv-rate.sh 3 3 3
shell&amp;gt; ./bin/adv-getratings.sh 1
3 3
2 2
shell&amp;gt; ./bin/adv-recommendall-source.sh 3 # prediction for user 3
4 4.00000
2 2.00000&lt;/code&gt;&lt;br/&gt;
I think my next post on adviserl will show a more useful example! :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/l5W9pEZflX8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/07/18/adviserl-got-a-gen_server-api.html</feedburner:origLink></entry>
 
 <entry>
   <title>object AND functional</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/KarHTgue2DA/object-and-functional.html" />
   <updated>2007-07-11T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/07/11/object-and-functional</id>
   <content type="html">From a programmer perspective, how easy (difficult) is it to mix OO and functional programming?&lt;br/&gt;
Earlier this year, I've been reading &lt;a href="http://mitpress.mit.edu/sicp/"&gt;SICP&lt;/a&gt; and &lt;a href="http://www.cs.bell-labs.com/cm/cs/pearls/"&gt;Programming pearls&lt;/a&gt; at the same time; Last month, I've been writing both OO Python code and functional Erlang code. Those experiences are probably the best feeling of programming I had since a while: I'm not writing code, I am coding abstractions.&lt;br/&gt;
But I'm still wondering about mixing both styles/paradigms in the same project or same code file. My intuition is that it may be nice to work with different styles for different parts of a program, but I would really be afraid to introduce such kind of mix in a project maintained by multiple programmers. Any experience to share on this subject?&lt;br/&gt;
Perhaps I should give &lt;a href="http://nemerle.org/Main_Page" target="_blank"&gt;Nemerle&lt;/a&gt; a try. Any other?&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/KarHTgue2DA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/07/11/object-and-functional.html</feedburner:origLink></entry>
 
 <entry>
   <title>Googling to learn collaborative filtering</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/lUxq_aJuO1A/googling-to-learn-collaborative-filtering.html" />
   <updated>2007-07-10T00:00:00+08:00</updated>
   <id>/wp-import/recommender/2007/07/10/googling-to-learn-collaborative-filtering</id>
   <content type="html">I have no idea what is a good way to discover and learn new things. Surely "science of learning" has some models and advices that may have been useful, but I choose to follow the lazy way. To learn about collaborative filtering, I googled.&lt;br/&gt;
The first source of information reported by the search engine is (of course?) wikipedia: &lt;a href="http://en.wikipedia.org/wiki/Collaborative_filtering" target="_blank"&gt;collaborative filtering &lt;/a&gt;.Then I passed 2 links in Google results (general information) to direct myself toward specialized articles through &lt;a href="http://jamesthornton.com/cf/" target="_blank"&gt;  this great personal page&lt;/a&gt;. I navigate a bit in it and with the help of few more Google searches I got lost ... on my way to be lost, at least I figure out some articles that seems fundamental: &lt;a href="http://www.citeulike.org/article/821182"&gt;Reporting and evaluating choices in a virtual community of use&lt;/a&gt;, &lt;a href="http://www.citeulike.org/article/3526"&gt;GroupLens: an open architecture for collaborative filtering of netnews&lt;/a&gt;, &lt;a href="http://www.citeulike.org/article/371866"&gt;Social information filtering: algorithms for automating 'word of mouth'&lt;/a&gt;. My machine learning background is appreciated at this stage.&lt;br/&gt;
But Wow! That's a lot of information: do I really understood what I read? This was time to got dirty hands so I choose one system looking relatively simple and faced it at implementation level: &lt;a href="http://en.wikipedia.org/wiki/Slope_One"&gt;Slope-One&lt;/a&gt; algorithm.&lt;br/&gt;
Then I found a recent article about &lt;a href="http://www.citeulike.org/user/lcoquelle/article/1288839"&gt;Google news personalization&lt;/a&gt; recommender system: I still don't feel comfortable to compare the different algorithms, but at least this great article put things in real context (taking into account the big scalability problem). And also this point me toward a wonderful survey: &lt;a href="http://www.citeulike.org/article/515044"&gt;Toward the Next Generation of Recommender Systems: A Survey of the State-of-the-Art and Possible Extensions&lt;/a&gt;.&lt;br/&gt;
I have enough (too much) information for now, so I guess that (1) it is why I feel a bit confused and (2) it is the good time to write down all that stuffs to try to organized it: field description and algorithms classifications,  evaluation of recommender systems (see for example &lt;a href="http://www10.org/cdrom/papers/519/node19.html" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://www.citeulike.org/user/lcoquelle/article/172550" target="_blank"&gt;here&lt;/a&gt;) and at last but not least the scalability problem. And I will try to use &lt;a href="http://www.citeulike.org/"&gt;citeUlike&lt;/a&gt; and its recommendations :)&lt;br/&gt;
Hopefully, after that, I can go further "&lt;a href="http://portal.acm.org/citation.cfm?id=1055714" target="_blank"&gt;Incorporating contextual information in recommender systems using a multidimensional approach&lt;/a&gt;" (&lt;a href="http://misrc.umn.edu/workingpapers/fullpapers/2004/0404_021004.pdf" target="_blank"&gt;available here&lt;/a&gt;), but before  I still have to find a survey of available recommender systems. Any recommendation? ;)&lt;br/&gt;
Did I miss something important?&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/lUxq_aJuO1A" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/recommender/2007/07/10/googling-to-learn-collaborative-filtering.html</feedburner:origLink></entry>
 
 <entry>
   <title>Adviserl goes live</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/cXMScaUgB48/adviserl-goes-live.html" />
   <updated>2007-07-06T00:00:00+08:00</updated>
   <id>/wp-import/adviserl/2007/07/06/adviserl-goes-live</id>
   <content type="html">Long time ago I wrote a very simple &lt;a href="http://www.daniel-lemire.com/fr/abstracts/SDM2005.html"&gt;Slope-One&lt;/a&gt; implementation (collaborative filtering algorithm): this was easy and fulfilled all my needs ... which was then to learn CF and Erlang ;).&lt;br/&gt;
Then I realized that it could be more than fun and could even become useful as a simple recommender system. So I wrote it as an OTP application and it is &lt;a href="http://code.google.com/p/adviserl/"&gt;published&lt;/a&gt; under GPLv3 license. Lots (lots!) of things still have to be done but the basic are like that:
&lt;pre&gt;% start application: by default use Slope-One data/algorithm
application:start(sasl),
application:start(adviserl),&lt;/pre&gt;
&lt;pre&gt;% add some rating in the system
adviserl:rate(1, 2,  {3, no_rating_data}), % user 1 rate item 2 with value 3 (no data)
adviserl:rate(1, 4,  {5, no_rating_data}), % ...
adviserl:rate(2, 2,  {1, no_rating_data}),
adviserl:rate(2, 5,  {8, "damn good!"}), % any data term can be associated to rating value
adviserl:rate(3, 4,  {3, no_rating_data}),
adviserl:rate(3, 5,  {2, no_rating_data}),
adviserl:rate(3, 12, {2, no_rating_data}),&lt;/pre&gt;
&lt;pre&gt;% some debug output to "see" the data
adv_ratings:print_debug(), % display the ratings per user
adv_items:print_debug(), % display a covisitation matrix&lt;/pre&gt;
&lt;pre&gt;% try some predictions
adviserl:recommend_all(1), % prediction for user 1
adviserl:recommend_all(2), % ... for user 2
adviserl:recommend_all(3),
adviserl:recommend_all(4),
adviserl:recommend_all([]), % for any user without rating!
adviserl:recommend_all([{2,5}]), % for any user having those ratings
adviserl:recommend_all([{4,5}]), % idem
adviserl:recommend_all([{2,5},{4,5}]), % idem with multiple ratings
adviserl:recommend_all([{3,5}]), % ... even if item is unknown&lt;/pre&gt;
&lt;pre&gt;% update on the fly
IncreaseRating = fun({R, Data}) -&amp;gt; {R + 1, Data} end,
DefaultRating = {1, no_data},
adviserl:rate(1, 2, {7, now()}), % user 1 change rating of item 2 from 3 to 7, adding data
adviserl:rate(1, 2, IncreaseRating, DefaultRating), % update from 7 to 8 with function
adviserl:rate(1, 42, IncreaseRating, DefaultRating), % rate item 42 at 1 (default)&lt;/pre&gt;
&lt;pre&gt;ok_lah.&lt;/pre&gt;
Among the main points on the &lt;a href="http://code.google.com/p/adviserl/wiki/Roadmap"&gt;pseudo roadmap&lt;/a&gt;:
&lt;ul&gt;
	&lt;li&gt; API to call adviserl functions through process messages&lt;/li&gt;
	&lt;li&gt;data persistence&lt;/li&gt;
	&lt;li&gt; data distribution&lt;/li&gt;
	&lt;li&gt;algorithm distribution&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/cXMScaUgB48" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/adviserl/2007/07/06/adviserl-goes-live.html</feedburner:origLink></entry>
 
 <entry>
   <title>Simple stream implementation in Erlang</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/78b0ZFy4G5o/44.html" />
   <updated>2007-05-07T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/05/07/44</id>
   <content type="html">My projects are all suspended ... I have been busy playing with &lt;a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5"&gt;stream examples of chapter 3 of SICP&lt;/a&gt; :).&lt;br/&gt;
I wrote in Erlang a simple implementation of stream as cons-list. It is not meant to be efficient but easy to understand (and debug):
&lt;ul&gt;
	&lt;li&gt;a stream is here a tuple &lt;span style="font-family:courier new,monospace;"&gt;{stream, Head, DelayedTail}&lt;/span&gt;, where &lt;span style="font-family:courier new,monospace;"&gt;DelayedTail&lt;/span&gt; is a 0-arity's function which return the next stream element tuple;&lt;/li&gt;
	&lt;li&gt;a macro implements the delay function used to construct a stream tail:
&lt;span style="font-family:courier new,monospace;"&gt;-define(DELAY(Any), fun() -&amp;gt; Any end)&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
Note: the head is not delayed, and if we need a delayed head this probably means that we need a lazy-evaluation model, to which I'll come later. Using abstract functions, &lt;span style="font-family:courier new,monospace;"&gt;head/1&lt;/span&gt; to access current value and &lt;span style="font-family:courier new,monospace;"&gt;tail/1&lt;/span&gt; to force evaluation of next stream state, will enables to hook a memoization process if needed.
&lt;p style="text-align:center;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="text-align:left;"&gt;Anyway, the stream concatenation and the delay's macro are enough to build all stream manipulations. Here are some examples:&lt;/p&gt;&lt;br/&gt;
&lt;pre&gt;
% map: application of a procedure to all elements of a stream
map(Proc, Stream={stream, undefined, undefined}) -&amp;gt;
    % empty stream: do nothing
    Stream;
map(Proc, Stream) -&amp;gt;
    % apply Proc to current, and delay apply to all tail elements
    {stream, Proc(head(Stream)), ?DELAY(map(Proc, tail(Stream)))}&lt;br/&gt;
% filter elements of stream with respect to some predicate
filter(Pred, Stream={stream, undefined, undefined}) -&amp;gt;
    % empty stream: do nothing
    Stream;
filter(Pred, Stream={stream, _Head, _Tail}) -&amp;gt;
    Current = head(Stream),
    case Pred(Current) of
        true -&amp;gt;
            {stream, Current, ?DELAY(filter(Pred, tail(Stream)))};
        _False -&amp;gt;
            filter(Pred, tail(Stream))
    end.&lt;br/&gt;
% generalized map: apply proc to multiple streams (traverse streams "in parallel")
gmap(Proc, Streams=[First={stream, undefined,undefined}|_Others]) -&amp;gt;
    % assume all stream have the same length
    % found one stream empty: end of process
    First;
gmap(Proc, Streams=[First|_Others]) -&amp;gt;
    % create a list of heads
    Heads = lists:map(fun(S) -&amp;gt; stream:head(S) end, Streams),
    % create a generator of the list of tails
    FTails = fun() -&amp;gt; lists:map(fun(S) -&amp;gt; stream:tail(S) end, Streams) end,
    % result is the application to heads and delayed mapping to tails
    {stream, Proc(Heads), ?DELAY(gmap(Proc, FTails()))}.&lt;br/&gt;
&lt;/pre&gt;
And now, we have enough to use the streams:
&lt;pre&gt;
% explicit definition of infinite sequence of integers
explicit_integers_from(N) -&amp;gt;
    {stream, N, ?DELAY(explicit_integers_from(N+1))}.&lt;br/&gt;
% add values of 2 streams
add(S1, S2) -&amp;gt;
    gmap(fun([X,Y]) -&amp;gt; X + Y end, [S1, S2]).&lt;br/&gt;
% infinite sequence of Fibonacci numbers
fibs() -&amp;gt;
    {stream, 0, ?DELAY({stream, 1, ?DELAY(add(fibs(), tail(fibs())))}) }.&lt;br/&gt;
&lt;/pre&gt;
A bit more usefull: 2 infinite sequences of prime numbers. First one uses the sieve of Eratosthene; second one uses basic definition of prime: number not divisible by any previous primes.
&lt;pre&gt;
% Sieve of Eratosthene:&lt;br/&gt;
sieve(Stream) -&amp;gt;
    Current = head(Stream),
    {stream, Current, ?DELAY(sieve(filter(
        fun(N) -&amp;gt; N rem Current /= 0 end,
        tail(Stream)
    )))}.&lt;br/&gt;
sieve_primes() -&amp;gt;
    sieve(explicit_integers_from(2)).&lt;br/&gt;
% prime numbers using the factors decomposition property&lt;br/&gt;
primes() -&amp;gt;
    {stream, 2, ?DELAY(filter(fun is_prime/1, explicit_integers_from(3)))}.&lt;br/&gt;
is_prime(N) -&amp;gt;
    iter_is_prime(N, primes()).&lt;br/&gt;
iter_is_prime(N, Primes) -&amp;gt;
    FirstPrime = head(Primes),
    if
        FirstPrime * FirstPrime &amp;gt; N -&amp;gt;
            true;
        N rem FirstPrime == 0 -&amp;gt;
            false;
        true -&amp;gt;
            iter_is_prime(N, tail(Primes))
    end.&lt;br/&gt;
&lt;/pre&gt;
And of course there are lot of stream examples in SICP chapter, like the impressive Euler transformation to accelerate convergence of sequence.&lt;br/&gt;
In this thread &lt;a href="http://erlang.mirror.su.se/ml-archive/erlang-questions/200010/msg00165.html" target="_blank"&gt;http://erlang.mirror.su.se/ml-archive/erlang-questions/200010/msg00165.html &lt;/a&gt; you can find a real stream implementation by Richard Carlsson, as well as interesting discussions about stream and lazy evaluation. Also check this other thread &lt;a href="http://www.erlang.org/ml-archive/erlang-questions/200602/msg00003.html" target="_blank"&gt; http://www.erlang.org/ml-archive/erlang-questions/200602/msg00003.html&lt;/a&gt; if you're interested by memoization in Erlang. I may test it later to learn the magic of Erlang parse_transform ;), but I think an easy possible way to implement memoization for my stream is to model a stream as a tuple of 4 elements, adding a dictionary of memoized values as last element (my current implementation uses the process dictionary to store memoized values).&lt;br/&gt;
Actually I'm not sure if this post is too short to be a tutorial or too long to be a interesting post! Anyway, it exists now ;) ... mostly because a friend gave me motivation to do so, thanks!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/78b0ZFy4G5o" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/05/07/44.html</feedburner:origLink></entry>
 
 <entry>
   <title>Programmers everywhere!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/YtlaMO2efd8/programmers-everywhere.html" />
   <updated>2007-04-28T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/04/28/programmers-everywhere</id>
   <content type="html">In last point of one of &lt;a href="http://khigia.wordpress.com/2007/03/31/some-articles-and-why-they-surprised-me/" target="_blank"&gt;this previous post&lt;/a&gt; I was remembering (to me!) the need to know the roots of computer science. Since then, I read (began to...) some interesting articles on wikipedia: &lt;a href="http://en.wikipedia.org/wiki/History_of_computer_science" target="_blank"&gt;history of CS&lt;/a&gt;, the &lt;a href="http://en.wikipedia.org/wiki/List_of_prominent_pioneers_in_computer_science" target="_blank"&gt;  pioners&lt;/a&gt;, the list of &lt;a href="http://en.wikipedia.org/wiki/Turing_Award" target="_blank"&gt; Turing award winners&lt;/a&gt; ... wikipedia is really time consuming!&lt;br/&gt;
Curiously, it's more difficult to find a good list of modern computer scientists (or programmers, as they prefer). I like the post &lt;a href="http://www.memestreams.net/users/pnw/blogid770893/" target="_blank"&gt;   Beautiful Code: Leading Programmers Explain How They Think&lt;/a&gt;. Any other recommendation?&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/YtlaMO2efd8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/04/28/programmers-everywhere.html</feedburner:origLink></entry>
 
 <entry>
   <title>SICP, concurrency and time</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/VHS3FJIs4iA/sicp-concurrency-and-time.html" />
   <updated>2007-04-28T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/04/28/sicp-concurrency-and-time</id>
   <content type="html">This was too simple, so why wasn't I aware of that? concurrency and time is the same thing ... or &lt;a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-23.html#%25_sec_3.4"&gt;at least you cannot have one without the other&lt;/a&gt;, logic!
I'm currently in a "back to basic" phase ... but I don't have enough time: how can I manage to implement stream, while reading the meta-circular evaluator chapter, and also having a "normal" life? time and concurrency ...&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/VHS3FJIs4iA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/04/28/sicp-concurrency-and-time.html</feedburner:origLink></entry>
 
 <entry>
   <title>8-queens ... me too!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/8anj3Gue4D8/8-queens-me-too.html" />
   <updated>2007-04-10T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/04/10/8-queens-me-too</id>
   <content type="html">Even it the &lt;a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle"&gt;8-queens puzzle&lt;/a&gt; is often used to illustrate the recursivity principle, I never tried to solve it myself. I only wrote my N-queens solution recently (using Erlang), and was pretty happy to see that &lt;a href="http://en.wikipedia.org/wiki/List_comprehension"&gt;list-comprehension&lt;/a&gt; is quite good for the principle of generate-and-filter. Oh! and I tried the &lt;a href="http://esdl.sourceforge.net/"&gt;ESDL&lt;/a&gt; library to display the result :) ... I was just as excited as the day I did my first openGL tutorial in C.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/8anj3Gue4D8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/04/10/8-queens-me-too.html</feedburner:origLink></entry>
 
 <entry>
   <title>Positive integer and recursion</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/hdL-l7SMNWc/positive-integer-and-recursion.html" />
   <updated>2007-04-05T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/04/05/positive-integer-and-recursion</id>
   <content type="html">I remember my first steps of Prolog, I was following an exercise to define positive integer as a recursion of the same function ... I did not really known why I did that, but it was fun to define the integers (the funniest Prolog exercise is still to write a Prolog interpretor in Prolog). Today I'm reading &lt;a href="http://mitpress.mit.edu/sicp/full-text/book/book.html"&gt;SICP&lt;/a&gt; and I just found in Ex2.6 that the recursive integer definition is the basic of lambda calculus: Church' numerals! Definitively, I have to learn this lambda calculus. At least I have now a better understanding of it (&lt;a href="http://www.rubrication.net/2007/01/13/addition-in-the-lambda-calculus/"&gt;thanks also to this post&lt;/a&gt;) and I wrote &lt;a href="http://paste.lisp.org/display/39267"&gt;the addition and multiplication operators in Erlang&lt;/a&gt;.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/hdL-l7SMNWc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/04/05/positive-integer-and-recursion.html</feedburner:origLink></entry>
 
 <entry>
   <title>grinderl is sinan-ized</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/86iPua3AWik/grinderl-is-sinan-ized.html" />
   <updated>2007-04-05T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/04/05/grinderl-is-sinan-ized</id>
   <content type="html">Forgot to mention: &lt;a href="http://code.google.com/p/grinderl"&gt;grinderl&lt;/a&gt; now use &lt;a href="http://code.google.com/p/sinan/"&gt;sinan&lt;/a&gt; as build system (makefiles are still around but should disappear as soon as the tests will be handle by sinan). Hopefully sinan will help to deals with dependencies and release handling.&lt;br/&gt;
Btw I continue to follow the development of the &lt;a href="http://cean.process-one.net/" target="_blank"&gt;CEAN&lt;/a&gt; repository ...
&lt;a href="http://cean.process-one.net/" target="_blank"&gt; &lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/86iPua3AWik" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/04/05/grinderl-is-sinan-ized.html</feedburner:origLink></entry>
 
 <entry>
   <title>Some articles and why they surprised me</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/u8uchkV-00o/some-articles-and-why-they-surprised-me.html" />
   <updated>2007-03-31T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/03/31/some-articles-and-why-they-surprised-me</id>
   <content type="html">
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.thinkingparallel.com/2007/02/26/softskills/" title="Softskills"&gt;Softskills&lt;/a&gt; blog post on &lt;a href="http://www.thinkingparallel.com/"&gt;Thinking Parallel&lt;/a&gt; : I try my best to be open-minded ... but I would have never read this book before to read this post: I just don't like the title &lt;em&gt;"How to win friends &amp;amp; influence people"&lt;/em&gt;. But after the blog post, I realized it's a nice book I can read to learn about "how to behave as a good developer in a good team". Why am I so not understanding and stopped at the title!? stupid me!&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://www.librarything.com/thingology/2007/02/when-tags-works-and-when-they-dont.php"&gt;Tags efficienty at Amazon vs. LibraryThing&lt;/a&gt; : before to read this article, I almost forgot that users of a system don't care to give input to this system! We, as users, only have one objective to target, and system should be transparent. UX Design rules.&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://swtch.com/~rsc/regexp/regexp1.html"&gt;Regular expression can be simple and fast&lt;/a&gt; :What!? This time I almost forgot that from all the good software applications around the world, there is probably very few which come from a long scientific study of the subject, with design comparisons and efficiency implementation tests! Most of them come from an idea, quickly throw one day as a piece of code, and evolving as the project mature. I should never forget again: enough is enough! (still, regular expressions with automata is a basic of computer science: don't forget the basics!)&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/u8uchkV-00o" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/03/31/some-articles-and-why-they-surprised-me.html</feedburner:origLink></entry>
 
 <entry>
   <title>grinderl: less tsung, more capistrano</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/pz6t2dkkAmU/grinderl-less-tsung-more-capistrano.html" />
   <updated>2007-03-31T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/03/31/grinderl-less-tsung-more-capistrano</id>
   <content type="html">I decided to change the roadmap of the &lt;a href="http://code.google.com/p/grinderl/"&gt;grinderl&lt;/a&gt; project.&lt;br/&gt;
It first application was to be a tiny load-test framework (at least a testing framework as I'm not sure it is efficient enough to create heavy load on a well design server). And I still have to finish the part of creating useful statistics from all the results.&lt;br/&gt;
But now I think that I could implement a better node management API, and then grinderl can become one way to call code on remote host (not exactly as RPC since command are asynchronous and supervised by remote host). One application could be to install an external application on all remote host, or manage deployment like does &lt;a href="http://manuals.rubyonrails.com/read/book/17"&gt;capistrano&lt;/a&gt; (but with the full Erlang environment available!).&lt;br/&gt;
So the new (of course, it's the first!) roadmap:
&lt;ul&gt;
	&lt;li&gt; Stabilize the current version:
&lt;ul&gt;
	&lt;li&gt; move test to become command&lt;/li&gt;
	&lt;li&gt; better handling of results sent by remote hosts&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
	&lt;li&gt; Develop concurrently the remote node API and a UI:
&lt;ul&gt;
	&lt;li&gt; API to manage remote hosts
&lt;ul&gt;
	&lt;li&gt;use slave module&lt;/li&gt;
	&lt;li&gt;have a look at &lt;a href="https://support.process-one.net/doc/display/ERL/Starting+a+set+of+Erlang+cluster+nodes"&gt;this how-to&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;can we install a minimal Erlang node on a remote machine through ssh ... using CEAN or erlware maybe?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
	&lt;li&gt;UI: network tools seems to require a network-able UI (probably using yaws) to be able to:
&lt;ul&gt;
	&lt;li&gt; see/manage nodes/hosts&lt;/li&gt;
	&lt;li&gt; send command to all/any hosts, monitor results (looks like each command will need a specialize UI)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
Conclusion:
&lt;ul&gt;
	&lt;li&gt;Sad note: nothing new in grinderl (this project don't seems to appeal my creativity)&lt;/li&gt;
	&lt;li&gt;Good note: simple project to learn Erlang distributed programming&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/pz6t2dkkAmU" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/03/31/grinderl-less-tsung-more-capistrano.html</feedburner:origLink></entry>
 
 <entry>
   <title>List of Erlang data structures</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/6HF-mKA24LQ/list-of-erlang-data-structures-stdlib-contrib.html" />
   <updated>2007-02-24T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/02/24/list-of-erlang-data-structures-stdlib-contrib</id>
   <content type="html">How would you implement a huge-but-sparse 2D matrix in Erlang?
&lt;ul&gt;
	&lt;li&gt;First solution who came to my mind was to google for some linear algebra library ... that failed!&lt;/li&gt;
	&lt;li&gt;The second one, implement a dict-of-dict structure.&lt;/li&gt;
&lt;/ul&gt;
That was quite easy, but as I was wondering on efficiency I needed to understand differences between dict, orddict etc. On my way I came up with this (ongoing) &lt;a href="http://khigia.wordpress.com/erlang-data-structures/"&gt;list of Erlang data structures&lt;/a&gt;.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/6HF-mKA24LQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/02/24/list-of-erlang-data-structures-stdlib-contrib.html</feedburner:origLink></entry>
 
 <entry>
   <title>Simple problem ... looking for simple solution</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/R3gxMcSGTrc/simple-problem-looking-for-simple-solution.html" />
   <updated>2007-02-24T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/02/24/simple-problem-looking-for-simple-solution</id>
   <content type="html">I use Vim in a Gnome Terminal in a Ubuntu/Gnome desktop, with the terminal fullscreen mode option ... and thus can't see the popups of Gaim/Skype (I don't want to use the sound alert to not disturb my colleagues)! I would love to see the small message near tray icon that I normally got in "not-terminal-fullscreen mode". Maybe I should switch back to XFCE ...&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/R3gxMcSGTrc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/02/24/simple-problem-looking-for-simple-solution.html</feedburner:origLink></entry>
 
 <entry>
   <title>GMailReader</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/8G1sbcE3gk0/gmailreader.html" />
   <updated>2007-02-15T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/02/15/gmailreader</id>
   <content type="html">I used GReader since few months now, it works pretty well ... it's maybe too good: now I would like to read my email in GMail with the same presentation as GReader! (i.e. don't hide the other emails when I click on one, but only expand the text of the selected email).&lt;br/&gt;
I know about some tools to do the opposite (send email from feeds) like the excellent &lt;a href="http://www.rssfwd.com"&gt;RSSFwd&lt;/a&gt;. So after the question "what's the difference betweens a forum and a blog?", here comes "what's the differences between a feed and a (thread of) emails?". Can I say that every email is a feed (with one post), to which I can participate (the thread of emails becoming a feed with more than one post).&lt;br/&gt;
Some days I really have stupid blog post, and I'm happy to not have to read my blog :)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/8G1sbcE3gk0" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/02/15/gmailreader.html</feedburner:origLink></entry>
 
 <entry>
   <title>clap clap clap</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/dqhuUhxc7jg/clap-clap-clap.html" />
   <updated>2007-02-12T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/02/12/clap-clap-clap</id>
   <content type="html">
&lt;p align="center"&gt;&lt;strong&gt;Warning: this is a bad post!&lt;/strong&gt;&lt;/p&gt;
Applauding's time during meeting ... clap clap clap ... today (again) made me think to the sound of the steps of the "stupid mule" following the man who gives it the heavy duty! worst, the mule often carry the rewarding food it will got!&lt;br/&gt;
That's not that I don't ike to applaud: I do think &lt;em&gt;dedicate work&lt;/em&gt; and &lt;em&gt;recognize good work&lt;/em&gt; is really better than the work itself! But please, don't ask me to applaud ... I will do it by myself!&lt;br/&gt;
Yeah, I'm a bit sad/angry ... and I like to write in this mood ... and I LOVE/NEED blues music, my liberty universe!&lt;br/&gt;
Note: I'm sorry for those strong animals (mules), they're good!, I just needed a metaphor to express myself.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/dqhuUhxc7jg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/02/12/clap-clap-clap.html</feedburner:origLink></entry>
 
 <entry>
   <title>Teamwork</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/m99uLGe5R8A/teamwork.html" />
   <updated>2007-02-12T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/02/12/teamwork</id>
   <content type="html">Have you ever row in a quadruple scull's? in a 20 paddlers dragon boat? Efficiency is not a matter of individual strength, it's mostly a matter of synchronization!
And for that, team have to be organized ... why? to follow a common objective! that's the definition of a team. That's why hierarchical organization had been so successful: it obliged a single base! But it's maybe not optimal ...
Look at open source projects, really, &lt;a href="http://video.google.com/videoplay?docid=-4216011961522818645&amp;amp;q=poisonous+people"&gt;look at that&lt;/a&gt; (CK, thanks for the link)!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/m99uLGe5R8A" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/02/12/teamwork.html</feedburner:origLink></entry>
 
 <entry>
   <title>[priv] TaDa - readings</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/GQOiueCmzXw/tada-readings.html" />
   <updated>2007-02-12T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/02/12/tada-readings</id>
   <content type="html">See also &lt;a href="http://www.accesscom.com/~darius/personal/books.html"&gt;this list&lt;/a&gt; from &lt;a href="http://www.accesscom.com/~darius/"&gt;Darius  Bacon&lt;/a&gt;&lt;br/&gt;
&lt;strong&gt;Technical/Science document&lt;/strong&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.oecd.org/document/40/0,3343,fr_2649_37455_38800424_1_1_1_37455,00.html"&gt;Comprendre le cerveau : naissance d'une science de l'apprentissage&lt;/a&gt;&lt;/li&gt;
&lt;li class="check"&gt;&lt;a href="http://amazon.com/gp/registry/wishlist/2CF1JHHJC1RVV/ref=cm_wl_rlist_go/103-8097772-0421416"&gt;Amazon CS book wish-list&lt;/a&gt;&lt;/li&gt;
&lt;li class="check"&gt;&lt;img src="http://lcoquelle.tadalist.com/images/drag.gif?1169566980" alt="Drag" class="di_527435 dragger" style="display:none;" height="11" width="25" /&gt;&lt;a href="http://producingoss.com/"&gt; Producing Open Source Software&lt;/a&gt; (by subversion creator, see in &lt;a href="http://video.google.com/videoplay?docid=-4216011961522818645&amp;amp;q=poisonous+people"&gt;this video about poisonous people&lt;/a&gt;)&lt;/li&gt;
&lt;li class="check"&gt;Introduce aphordance in UX design.
&lt;ul&gt;
&lt;li class="check"&gt;The Design of Everyday Things, 1988, Donald Norman&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;strong&gt;General&lt;/strong&gt;
&lt;img src="http://lcoquelle.tadalist.com/images/drag.gif?1169566980" alt="Drag" class="di_527435 dragger" style="display:none;" height="11" width="25" /&gt;
&lt;ul&gt;
&lt;li class="check"&gt;THE Reference I never read :)&lt;span&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li class="check"&gt;The Society of Mind, Marvin Minsky&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="check"&gt;CRAP-ify your graphics design
&lt;ul&gt;
&lt;li class="check"&gt;&lt;span&gt;&lt;/span&gt;&lt;img src="http://lcoquelle.tadalist.com/images/drag.gif?1169566980" alt="Drag" class="di_527435 dragger" style="display:none;" height="11" width="25" /&gt; The non designer's design book: Design and Typographic Principles for the Visual Novice, Robin William&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="check"&gt;Wanna know about how to tell story?
&lt;ul&gt;
&lt;li class="check"&gt;Understanding Comics: The Invisible Art, Scott McCloud&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="check"&gt;Keep symphony in mind
&lt;ul&gt;
&lt;li class="check"&gt;Dialogue:the art of thinking together, William Isaacs&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class="check"&gt;Beethoven's Anvil: Music in Mind and culture, William Benzon&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="check"&gt;Meaning of life, positive psychology
&lt;ul&gt;
&lt;li class="check"&gt;Man's search for meaning, Viktor Frankl&lt;/li&gt;
&lt;li class="check"&gt;Authentic happiness, Martin E. P. Seligman&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="check"&gt;Right-handed brain ;)
&lt;ul&gt;
&lt;li class="check"&gt;Right hand, left hand:the origins of asymmetry in brains, bodie, atoms and cultures, Dr McManus
&lt;ul&gt;
&lt;li class="check"&gt;(author won an &lt;a href="http://www.improb.com/"&gt;Ig Nobel&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;strong&gt; Finance&lt;/strong&gt;
&lt;ul&gt;
	&lt;li&gt;Interesting (?) blog post about ETF (?) http://rlove.org/log/2007070601
&lt;span class="sans"&gt;&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;&lt;span class="sans"&gt;One Up On Wall Street : How To Use What You Already Know To Make Money In The Market, &lt;/span&gt;Peter Lynch and John Rothchild (&lt;a href="http://www.amazon.com/One-Up-Wall-Street-Already/dp/0743200403/ref=pd_bbs_2/104-5247049-0498344?ie=UTF8&amp;amp;s=books&amp;amp;qid=1183712536&amp;amp;sr=1-2"&gt;amazon link&lt;/a&gt;)&lt;/li&gt;
	&lt;li&gt;&lt;span class="sans"&gt;The Little Book That Beats the Market, &lt;/span&gt;Joel Greenblatt (&lt;a href="http://www.amazon.com/Little-Book-That-Beats-Market/dp/0471733067/ref=pd_bbs_sr_2/104-5247049-0498344?ie=UTF8&amp;amp;s=books&amp;amp;qid=1183712646&amp;amp;sr=1-2"&gt;amazon link&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/GQOiueCmzXw" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/02/12/tada-readings.html</feedburner:origLink></entry>
 
 <entry>
   <title>grinderl: early stage</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/KeaR8jQCRCA/grinderl-early-stage.html" />
   <updated>2007-02-10T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/02/10/grinderl-early-stage</id>
   <content type="html">I did it! I have try to code my first OTP applications following most of the recommendation of the documentation (and the French book &lt;a href="http://www.eyrolles.com/Informatique/Livre/index.php?ouv_ean13=9782212110791&amp;amp;societe=remond" target="_blank" title="//www.eyrolles.com/Informatique/Livre/index.php?ouv_ean13=9782212110791&amp;amp;societe=remond" class="externalLink"&gt;Erlang programmation&lt;/a&gt; was a great help).&lt;br/&gt;
One of those applications became an opensource project: &lt;strong&gt;grinderl&lt;/strong&gt;. I did blog a bit about it &lt;a href="http://khigia.wordpress.com/2006/11/25/baby-steps-in-the-erlang-world/" target="_blank" title="//khigia.wordpress.com/2006/11/25/baby-steps-in-the-erlang-world/" class="externalLink"&gt;in this blog post&lt;/a&gt;, and now it has evolved from the all-in-one-module code to a small ongoing project (&lt;a href="http://code.google.com/p/grinderl/" target="_blank" title="//code.google.com/p/grinderl/" class="externalLink"&gt;hosted by&lt;/a&gt; googlecode). To do that I used:
&lt;ul&gt;
	&lt;li&gt;application/supervisor/server/fsm/event ... all the generic modules: not complicated&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://support.process-one.net/doc/display/CONTRIBS/EUnit" title="eunit"&gt;eunit&lt;/a&gt;: simple enough, and tests should be compatible with the test_server application&lt;/li&gt;
	&lt;li&gt;dialyzer: wow! it can save a lot of time, especially because Erlang has no type system: a MUST.&lt;/li&gt;
	&lt;li&gt; appmon: great and easy to see your supervision tree&lt;/li&gt;
	&lt;li&gt; debugger: I still prefer to write message in the console ... please don't tell that to anybody!&lt;/li&gt;
	&lt;li&gt; edoc: I learned how to use it, but sadly it didn't teach me to write good documentation...&lt;/li&gt;
&lt;/ul&gt;
I may like to have a look at cover and profiling tools, I may want to learn about Erlang port, but I guess the two main points I missed are:
&lt;ul&gt;
	&lt;li&gt; mnesia: looks so great!&lt;/li&gt;
	&lt;li&gt; release handling: this is a tricky part of OTP application distribution I think!&lt;/li&gt;
&lt;/ul&gt;
And for the last one, I hope the &lt;a href="http://code.google.com/p/sinan/" target="_blank" title="//code.google.com/p/sinan/" class="externalLink"&gt;sinan built system&lt;/a&gt; can help me (&lt;a href="http://erlangish.blogspot.com/2007/02/code-complete.html" target="_blank" title="//erlangish.blogspot.com/2007/02/code-complete.html" class="externalLink"&gt;Eric Merritt promised us a high level user documentation&lt;/a&gt; soon).&lt;br/&gt;
My only regret is that I haven't found a complete tutorial to go through all the steps of transformation of an Erlang program in an OTP application release. And that's too sad that I don't feel able to write one!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/KeaR8jQCRCA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/02/10/grinderl-early-stage.html</feedburner:origLink></entry>
 
 <entry>
   <title>STM drive me to the Anarchy</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/uw-2ESA-RbE/stm-drive-me-to-the-anarchy.html" />
   <updated>2007-01-23T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/01/23/stm-drive-me-to-the-anarchy</id>
   <content type="html">STM stand for &lt;a href="http://en.wikipedia.org/wiki/Software_transactional_memory" target="_blank" title="//en.wikipedia.org/wiki/Software_transactional_memory" class="externalLink"&gt;Software Transactional Memory&lt;/a&gt;. How does it drive me to anarchy? because I get lost again following all the web links!&lt;br/&gt;
In fact I was wondering where to get some information about this mechanism used in some concurrency models. For those like me who like concrete explanation, I recommend to read &lt;a href="http://armstrongonsoftware.blogspot.com/2006/09/pure-and-simple-transaction-memories.html" target="_blank" title="//armstrongonsoftware.blogspot.com/2006/09/pure-and-simple-transaction-memories.html" class="externalLink"&gt;this blog post from Joe Armstrong&lt;/a&gt; then &lt;a href="http://lambda-the-ultimate.org/node/1964" target="_blank" title="//lambda-the-ultimate.org/node/1964" class="externalLink"&gt;beautiful concurrency&lt;/a&gt; for more details.&lt;br/&gt;
And if you are still wondering why I wrote the term "anarchy", it's just because I read about the work of &lt;a href="http://en.wikipedia.org/wiki/Audrey_Tang" target="_blank" title="//en.wikipedia.org/wiki/Audrey_Tang" class="externalLink"&gt;Audrey Tang&lt;/a&gt; who integrated STM in &lt;a href="http://www.pugscode.org/" target="_blank" title="//www.pugscode.org/" class="externalLink"&gt;Pugs (an Haskell implementation of Perl)&lt;/a&gt; ... and she also appears to be a proponent of the &lt;a href="http://en.wikipedia.org/wiki/Individualist_anarchism" target="_blank" title="//en.wikipedia.org/wiki/Individualist_anarchism" class="externalLink"&gt;Individualist Anarchism&lt;/a&gt;.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/uw-2ESA-RbE" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/01/23/stm-drive-me-to-the-anarchy.html</feedburner:origLink></entry>
 
 <entry>
   <title>Erlang: the good, the bad and the chubby</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/yx11mdIOSss/erlang-the-good-the-bad-and-the-chubby.html" />
   <updated>2007-01-23T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2007/01/23/erlang-the-good-the-bad-and-the-chubby</id>
   <content type="html">(hoping my &lt;a href="http://www.popachubby.com/" target="_blank" title="//www.popachubby.com" class="externalLink"&gt;favorite guitarist&lt;/a&gt; don't mind that I borrow one of &lt;a href="http://www.bluesweb.com/p_disque.php3?id_article=286" target="_blank" title="//www.bluesweb.com/p_disque.php3?id_article=286" class="externalLink"&gt;his title&lt;/a&gt;)&lt;br/&gt;
Some (mostly subjective) comments after few days playing around Erlang:
&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt; The good:&lt;/strong&gt; I have never before implemented a server (relatively efficient TCP proxy) so quickly. Asynchronous call are as easy as synchronous ones and network is invisible! that's good! physician can wrote as many differential equation as they need, synchronous model are a &lt;strong&gt;strong&lt;/strong&gt; hypothesis of the world!&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt; The bad:&lt;/strong&gt; syntax! I was used to &lt;a href="http://en.wikipedia.org/wiki/Prolog" target="_blank" title="//en.wikipedia.org/wiki/Prolog" class="externalLink"&gt;Prolog&lt;/a&gt; notation, but Erlang introduce too many meaning for punctuation while newline or indentation has no meaning at all! Anybody interested in Pyerlang (a syntax translator python-inspired)?&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt; The chubby:&lt;/strong&gt; my next blog will be about transformation of a simple Erlang server to a (nearly) complete OTP application. Yes, OTP is a good framework, but learning it is far to be as easy as learning Erlang!&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/yx11mdIOSss" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2007/01/23/erlang-the-good-the-bad-and-the-chubby.html</feedburner:origLink></entry>
 
 <entry>
   <title>Music comes from here!?!!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/HyvUKP37PWE/music-comes-from-here.html" />
   <updated>2007-01-23T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/01/23/music-comes-from-here</id>
   <content type="html">This evening my &lt;a href="http://pandora.com/" target="_blank" title="//pandora.com" class="externalLink"&gt;pandora&lt;/a&gt; radios navigate from Tab Benoit to Popa Chubby by Melvin Taylor, and from Buddy Guy to Robert Lowery ... even better than a random selection on my hard-drive since my collection is quite limited!&lt;br/&gt;
But &lt;em&gt;the evening's question&lt;/em&gt; is not about blues nor guitar, it is a question about physic: isn't my brain afraid of my headset? if my brain has a pure stereophonic analysis model to locate the sound source, it should conclude that it come from the center of my head, isn't it? ... I listen again, and yes, sound comes from there. Good brain, not as afraid as I am.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/HyvUKP37PWE" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/01/23/music-comes-from-here.html</feedburner:origLink></entry>
 
 <entry>
   <title>UX* Design</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/q9_YvP2Cp2s/ux-design.html" />
   <updated>2007-01-16T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/01/16/ux-design</id>
   <content type="html">I assisted to my first presentation about &lt;a href="http://en.wikipedia.org/wiki/User_experience_design" target="_blank" title="//en.wikipedia.org/wiki/User_experience_design" class="externalLink"&gt;User Experience Design&lt;/a&gt; (as I discovered, UX Design is not only UX). Here is a quick summary of what I still remember.&lt;br/&gt;
From what I understood UX Design is defined by:
&lt;ul&gt;
	&lt;li&gt;  aesthetic&lt;/li&gt;
	&lt;li&gt;  functionality&lt;/li&gt;
	&lt;li&gt;  innovation&lt;/li&gt;
	&lt;li&gt;  enterprise impact&lt;/li&gt;
	&lt;li&gt;  human factor (~ergonomics)&lt;/li&gt;
&lt;/ul&gt;
A product specification can then be described by a list of features, where each feature is defined by:
&lt;ul&gt;
	&lt;li&gt;  description (what is/does it?)&lt;/li&gt;
	&lt;li&gt;  functional test (how to test the functionality?)&lt;/li&gt;
	&lt;li&gt;  intend or goal (what's the objective of the feature, for e.g. "make user happy")&lt;/li&gt;
	&lt;li&gt;  how to test/measure the feature (particularly its goal)&lt;/li&gt;
&lt;/ul&gt;
Relative reading (added in my reading queue):
&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;The Design of Everyday Things&lt;/em&gt; [Donald Norman, 1988]&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;D. Norman introduced the term affordance about user interaction, and emphasize on the design of product: "make the task dominate, make the tool invisible".&lt;/blockquote&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/q9_YvP2Cp2s" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/01/16/ux-design.html</feedburner:origLink></entry>
 
 <entry>
   <title>Thread, Event, and concurrency model</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/ZvZgyafL_IA/thread-event-and-concurrency-model.html" />
   <updated>2007-01-16T00:00:00+08:00</updated>
   <id>/wp-import/general/2007/01/16/thread-event-and-concurrency-model</id>
   <content type="html">I recently jumped into the &lt;a href="http://www.erlang.org/" title="Erlang.org Homepage" target="_blank"&gt;Erlang&lt;/a&gt; world, mostly seduced by the message-passing concurrency model (as opposed to the shared-state concurrency model) [1]. This was a choice &lt;strong&gt;a priori&lt;/strong&gt; without real objective (I mean without project, just as learning experience).&lt;br/&gt;
Now we have (project in my company) to implement an "efficient" and scalable server: fast, robust and highly-available (as any servers, of course). Coming from a really bad Python threaded-server experience, I'd rather read some hints before to go to any platform or framework (&lt;a href="http://www.stackless.com/" title="Stackless Python Homepage"&gt;Stackless Python&lt;/a&gt;, &lt;a href="http://twistedmatrix.com/" title="Twisted Framework Homepage"&gt;Twisted&lt;/a&gt;, Erlang/OTP, Java, C/C++ ...). Here are some available documents related to high performance network servers:
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.kegel.com/c10k.html" target="_blank" title="//www.kegel.com/c10k.html" class="externalLink"&gt;The C10K problem&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://pl.atyp.us/content/tech/servers.html" target="_blank" title="//pl.atyp.us/content/tech/servers.html" class="externalLink"&gt;High Performance Server Architecture&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://www.usenix.org/events/hotos03/tech/vonbehren.html" target="_blank" title="//www.usenix.org/events/hotos03/tech/vonbehren.html" class="externalLink"&gt;Why events are a bad idea&lt;/a&gt; (with &lt;a href="http://lambda-the-ultimate.org/classic/message10796.html" target="_blank" title="//lambda-the-ultimate.org/classic/message10796.html" class="externalLink"&gt;relative comments&lt;/a&gt; on &lt;a href="http://lambda-the-ultimate.org/" target="_blank" title="//lambda-the-ultimate.org" class="externalLink"&gt;LtU&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
Wow! that's tough to decide anything! Where I'm a bit surprised is that concurrency model choice is often viewed as &lt;span style="font-weight:bold;"&gt;Thread vs. Event&lt;/span&gt;, and each side argue about &lt;span style="font-style:italic;"&gt;throughput&lt;/span&gt; , &lt;span style="font-style:italic;"&gt;switching context cost&lt;/span&gt;, and &lt;span style="font-style:italic;"&gt;latency&lt;/span&gt;. As I understand, message-passing and event is not the same: most of the event model I've seen do not enable pre-emption without relying on threads to manage some event loops. And I naively assume that pre-emption is a good choice to implement robust and available server.&lt;br/&gt;
To conclude, if I have to choose something today, I would still choose Erlang! Because it implements efficient lightweight process: easy as threads, message passing model, and pre-emption able [2]. Furthermore Erlang proposes through OTP a whole framework for robust application, and I see a (good) framework as an invaluable experienced-user knowledge (thank you OTP folks!).&lt;br/&gt;
Notes:
[1] Indeed Erlang feature an efficient implementation of so-called processes (also known as lightweight-thread, micro-thread, greenlet or tasklet ... but the term process emphasize on the absence of shared-state common to many thread implementation). Erlang made also the choice of functional programming style as a programming guide to context independent code (unique affectation of variable, reduced side-effects).&lt;br/&gt;
[2] Having a lot of Python code, I had to compared Erlang vs. Stackless Python. In fact they share a lot of characteristics but Stackless has not the whole OTP framework and more importantly Stackless message sending block if there is no receptor of the message (more in &lt;a href="http://programming.reddit.com/info/u2ng/comments" target="_blank" title="//programming.reddit.com/info/u2ng/comments" class="externalLink"&gt;this discussion&lt;/a&gt; about Stackless vs. Erlang).&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/ZvZgyafL_IA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2007/01/16/thread-event-and-concurrency-model.html</feedburner:origLink></entry>
 
 <entry>
   <title>meta-musico-post</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/cQiwzwitNGU/meta-musico-post.html" />
   <updated>2006-12-11T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/12/11/meta-musico-post</id>
   <content type="html">What should contain my blog-posts? (sorry, I'm quite new in blogging world...)&lt;br/&gt;
Anyway, question is: should I post from time to time on the music I like or should I make a web page to gather all? Ok, nobody care ... but if you have time, have a look at  &lt;a href="http://www.musicovery.com/index.php?ct=us"&gt;musicovery&lt;/a&gt;, it's beautiful and fit well in my graph-oriented brain (I have a dream project called orgraphizer, but it's still more a dream than a project).&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/cQiwzwitNGU" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/12/11/meta-musico-post.html</feedburner:origLink></entry>
 
 <entry>
   <title>To do or not to do?</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/1KXRYWtW-Zc/to-do-or-not-to-do.html" />
   <updated>2006-11-27T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/27/to-do-or-not-to-do</id>
   <content type="html">I did mistakes (I mean I discover some new ones).&lt;br&gt;I implemented programming tools, some of them far too quickly to provide them a good architecture. At this time, I only needed few functionalities, but as requests came I implemented some quick-fix/quick-adds. And now, even if we don't planned to use those tools any further, I have to maintain those becomed-crappy-tools!&lt;br&gt;Too conclusions, choose one depending of your mood:&lt;br&gt;&lt;ul&gt;&lt;li&gt;Don't do anything before to be requested to do so; don't provide tools, keep it secret.&lt;/li&gt;&lt;li&gt;Never implement software without specifications and stay humble: never never never do quick design before to be a expert/guru/grand-master/programming-giant/computer-god!&lt;/li&gt;&lt;/ul&gt; &lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/1KXRYWtW-Zc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/27/to-do-or-not-to-do.html</feedburner:origLink></entry>
 
 <entry>
   <title>Baby steps in the Erlang world!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/PqsiUKOt1RA/baby-steps-in-the-erlang-world.html" />
   <updated>2006-11-25T00:00:00+08:00</updated>
   <id>/wp-import/erlang/2006/11/25/baby-steps-in-the-erlang-world</id>
   <content type="html">It took a long time to decide &lt;a href="http://khigia.wordpress.com/2006/11/02/what-is-my-next-programming-language/" title="to learn Erlang instead of Haskell or OCaml/F#"&gt;to learn Erlang instead of Haskell or OCaml/F#&lt;/a&gt;. What I really want to learn for now are the OTP principles of distributed application. So I wrote my first Erlang script (not yet an application) and it confirmed my point of view: Erlang make easy the development of distributed program! really!!!&lt;br/&gt;
At my work we needed to test performance of a TCP server (and we'll used Grinder because most of our API is Python). I've decided to use Erlang to do the same thing as an exercise: grind.erl (of course it will never become neither as huge as &lt;a href="http://grinder.sourceforge.net/" title="Grinder"&gt;Grinder&lt;/a&gt; neither as efficient as &lt;a href="http://tsung.erlang-projects.org/" title="Tsung"&gt;Tsung&lt;/a&gt;; I even do not hope it can be usefull). But with few lines of code, I was able to reproduce the same behavior as Grinder: launch on multiple machine multiple tester agents executing some test function and gather the results of all the tests.&lt;br/&gt;
Ok, I did not told all the truth: that's not a very small number of lines: arround 260 (with tests and all). But all the code is for running multiple time a test function and gathering some statistics on its result (run_task). Distributed this behaviour among multiple Erlang node is only a map call (distribute_task)!&lt;br/&gt;
Here is a code extract:
&lt;pre&gt;
distribute_task(NodeLst, Task) -&amp;gt;
    NodeLstLen = length(NodeLst),
    StatListener = spawn(grind, statistic_gathering, [now(), NodeLstLen]),
    io:format(
        "~w create statistic gathering process ~w on node ~w~n",
        [self(), StatListener, node()]
    ),
    TaskRunnerCreator = fun(Node) -&amp;gt; spawn(
        Node,
        grind,
        run_task,
        [StatListener, Task]
    ) end,
    Runners = lists:map(TaskRunnerCreator, NodeLst),
    io:format(
        "~w create a list of task runners: ~w~n",
        [self(), Runners]
    ),
    Runners.&lt;/pre&gt;
And here is a usage example:
&lt;pre&gt;
grind:init([node(), grinderl@node.net]).
grind:distribute_task(
        [node(), grinderl@node.net], % use 2 nodes
        {
            % on each node run the test function in 50 concurrent process
            {concurrent, 50},
            % two statistics to gather
            [{mean, writetime}, % a real value (mean, std. dev., min, max, med will be retrieved
             {count, writer_val} % a occurence counter
            ],
            % foo function to test: must return a tuple {ok|error, Pid, ValLst}
            fun(Writer, WritenValue) -&amp;gt;
                FWrite = fun() -&amp;gt; io:format("~s got ~w~n", [Writer, WritenValue]) end,
                {WriteTime, _Res} = timeit(FWrite),
                {ok, self(), [WriteTime, {Writer, WritenValue}]}
            end,
            % arguments to used for each call of the test function
            [{rr, ["bea", "pouf"]}, % first is taken in the list with a round-robin style
             {choice, [0, 1, 12, 42, 77]} % second argument is randomly choosen from the list
            ]
        }
    )&lt;/pre&gt;
This first steps was to become more familiar with Erlang language. My next steps will be:
&lt;ul&gt;
	&lt;li&gt;     use edoc ...&lt;/li&gt;
	&lt;li&gt;     use logger/trace services instead of printing every function call&lt;/li&gt;
	&lt;li&gt;     use generic services (gen_event, gen_server)&lt;/li&gt;
	&lt;li&gt;     create an OTP application (application, supervisor)&lt;/li&gt;
	&lt;li&gt;     use Mnesia to gather statistics&lt;/li&gt;
	&lt;li&gt;       what about OTP release&lt;/li&gt;
	&lt;li&gt;     embed everything in distribution package (automake/autoconf ?)&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/PqsiUKOt1RA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/erlang/2006/11/25/baby-steps-in-the-erlang-world.html</feedburner:origLink></entry>
 
 <entry>
   <title>Becoming nerd...</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/PbyLbyQHzjM/becoming-nerd.html" />
   <updated>2006-11-15T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/15/becoming-nerd</id>
   <content type="html">Oh no! I will become a real nerd if I continue to laugh at those stupid (and so gr8) jokes!&lt;br&gt; &lt;a href="http://xkcd.com/c184.html" title="http://xkcd.com/c184.html"&gt;http://xkcd.com/c184.html&lt;/a&gt;&lt;br&gt; Only one excuse: I used to work in 3D computer graphics field ...&lt;br&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/PbyLbyQHzjM" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/15/becoming-nerd.html</feedburner:origLink></entry>
 
 <entry>
   <title>To Zune or not to Zune</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/oYI3FbEOXqk/to-zune-or-not-to-zune.html" />
   <updated>2006-11-14T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/14/to-zune-or-not-to-zune</id>
   <content type="html">&lt;a title="Zune" href="http://www.zunescene.com"&gt;Zune&lt;/a&gt;: an iPod-like with Wi-Fi!&lt;br&gt;... but I don't like all the marketing stategy behind those products :(&lt;br&gt;Any iTux project?&lt;br&gt; &lt;br&gt;&lt;br&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/oYI3FbEOXqk" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/14/to-zune-or-not-to-zune.html</feedburner:origLink></entry>
 
 <entry>
   <title>Home Multimedia System</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/RrJmUTV6P_o/home-multimedia-system.html" />
   <updated>2006-11-10T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/10/home-multimedia-system</id>
   <content type="html">Since I read this &lt;a href="http://www.joelonsoftware.com/items/2006/11/10.html" title="post"&gt;post&lt;/a&gt;   from Joel Spolsky about &lt;a href="http://www.sonos.com/" title="Sonos"&gt;Sonos&lt;/a&gt;, I cannot wait anymore to get such a cool wireless distributed system everywhere in my house ... but I will try to wait a bit more for two reasons: first my house is too small :), second I would like the same kind of system but also including video.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/RrJmUTV6P_o" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/10/home-multimedia-system.html</feedburner:origLink></entry>
 
 <entry>
   <title>Pacstatistics</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/nl3Mu4UheJg/pacstatistics.html" />
   <updated>2006-11-04T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/04/pacstatistics</id>
   <content type="html">&lt;img src="http://docs.google.com/File?id=dhjmr8f_28d9fxbj" height="280" width="442" /&gt;
(from &lt;a href="http://www.thehumorarchives.com/joke/PacMan_pie_chart" title="the humor archives"&gt;the humor archives&lt;/a&gt;)&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/nl3Mu4UheJg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/04/pacstatistics.html</feedburner:origLink></entry>
 
 <entry>
   <title>My next programming language</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/Rgl7hHWQDxA/what-is-my-next-programming-language.html" />
   <updated>2006-11-02T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/02/what-is-my-next-programming-language</id>
   <content type="html">&lt;span style="font-style:italic;"&gt;... This is a personal message address to me in future ...&lt;/span&gt;&lt;br/&gt;
&lt;span style="font-weight:bold;"&gt;   What is my next programming language?&lt;/span&gt;&lt;br/&gt;
&lt;a href="http://scala.epfl.ch/" title="Scala"&gt;Scala&lt;/a&gt; ,   &lt;a href="http://research.microsoft.com/fsharp/fsharp.aspx" title="F#"&gt;F#&lt;/a&gt; ,   &lt;a href="http://www.haskell.org/haskellwiki/Haskell" title="Haskell"&gt;Haskell&lt;/a&gt;   , &lt;a href="http://caml.inria.fr/" title="OCaml"&gt;OCaml&lt;/a&gt; or   &lt;a href="http://www.erlang.org" title="Erlang"&gt;Erlang&lt;/a&gt;?&lt;br/&gt;
Yes, my next language will be &lt;span style="font-style:italic;"&gt;functional&lt;/span&gt;, and I will focus on improving my skills in &lt;span style="font-style:italic;"&gt;concurrent programming&lt;/span&gt; and &lt;span style="font-style:italic;"&gt;distributed applications&lt;/span&gt;. And here come the reasons for the choice of the above shortlisted languages:
&lt;ul&gt;
	&lt;li&gt;     I just experimented the threading system of Python ... that really not fair     guys, so I quit Python!&lt;/li&gt;
	&lt;li&gt;     Scala use the Java threading model, that's good as far as I know (and Scala     looks fine!);&lt;/li&gt;
	&lt;li&gt;     F# enable to use all .NET library so I could experimented Tao on Mono (.NET     threading is also good, IronPython rocks);&lt;/li&gt;
	&lt;li&gt;     Haskell is pure ... I'm curious to understand those mysterious monads;&lt;/li&gt;
	&lt;li&gt;     OCaml mixes functional and imperative ... really efficient and yet simple;&lt;/li&gt;
	&lt;li&gt;     Erlang embed asynchronous model inside the language ... concurrent and yet     simple.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="font-weight:bold;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;strong&gt;Why concurrent programming? Why distributed?&lt;/strong&gt;&lt;br/&gt;
Nowadays computers aim to solve complex systems: large amount of data to process, large number of interactions, or naturally distributed systems. Parrallelism and distribution seems to be in the pipeline with multi-core processors and clusters supported onto a network more and more efficient (optic-fiber at home by example). Without looking at language theory (see &lt;a href="http://lambda-the-ultimate.org/node/1805" title="Future of software design?"&gt;Future of software design?&lt;/a&gt;), my next language has to enable a software design with those intrinsic features: parallelism (data or computing) and distribution.
&lt;span style="font-weight:bold;"&gt;&lt;/span&gt;&lt;br/&gt;
&lt;span style="font-weight:bold;"&gt;And why functional?&lt;/span&gt;&lt;br/&gt;
I don't really know ... for the fun??? I read a lot about Haskell recently; I just want to change my mind with another programming   paradigm, and I secretly hope that my functional code will be better optimized   on multicore machine. If you want real justification you may have a look at &lt;a href="http://www.defmacro.org/ramblings/fp.html" title="Functional Programming For The Rest of Us"&gt;Functional Programming For The Rest of Us&lt;/a&gt; or &lt;a href="http://www.linuxjournal.com/article/8850" title="Everything Your Professor Failed to Tell You About Functional Programming"&gt;Everything Your Professor Failed to Tell You About Functional Programming&lt;/a&gt;.&lt;br/&gt;
&lt;span style="font-weight:bold;"&gt;   Final choice of my future language&lt;/span&gt;&lt;br/&gt;
Still have to choose one in the shortlisted choices, but with which criteria?
Type inference is a must (coz above all, any good programmer has a special quality: he's lazy). But I don't see a strong typing as a must-have: it sure solves problem, but not all, and in the end you still rely on unittesting.&lt;br/&gt;
Let's do a first cut in the shortlist based on personal assumption: .NET is a better platform than Java (wow!). So:
&lt;ul&gt;
	&lt;li&gt;remove Scala: F# offer same kind of possibilities using .NET;&lt;/li&gt;
	&lt;li&gt;remove OCaml: shares a common ML-like syntax with F# but F# offer .NET platform access where OCaml offer efficiency.&lt;/li&gt;
&lt;/ul&gt;
Haskell is pure but I prefer easy development aiming at concurrent and distributed programming, which is not part of the Haskell language itself. Then I have to choose between Erlang or F#: let's go for Erlang, let's concentrate on distributed development embedded in Erlang language. If later I really need/want .NET platform, it will still be good time to review all those choices adding new languages progress!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/Rgl7hHWQDxA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/02/what-is-my-next-programming-language.html</feedburner:origLink></entry>
 
 <entry>
   <title>Mirror neurons and understanding by imitation</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/ySmNuuefNuM/mirror-neurons-and-understanding-by-imitation.html" />
   <updated>2006-11-01T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/11/01/mirror-neurons-and-understanding-by-imitation</id>
   <content type="html"> Thanks to Hanna Wallach for pointed to some articles about &lt;a title="autism and mirror neurons" href="http://www.srcf.ucam.org/%7Ehmw26/join-the-dots/2006/10/17/mirror-neurons-and-autism"&gt;autism and mirror neurons&lt;/a&gt;  .&lt;br&gt;&lt;br&gt;In the field of agent simulation in a VR world, some AI method give to an agent a representation model of its world where it can simulate approximate behaviors of other agents before to take a decision of its action in its real (virtual) world: simulation of a virtual world inside a virtual world...&lt;br&gt;&lt;br&gt;But the first time I discovered this idea of "interpreting a model of other" was with &lt;a title="Hercule Poirot" href="http://en.wikipedia.org/wiki/Hercule_Poirot"&gt;Hercule Poirot&lt;/a&gt; who try to imitate the person he want to understand, and even some small movements (like the position of hands or the smile...) can help him to "take the place of other".&lt;br&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/ySmNuuefNuM" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/11/01/mirror-neurons-and-understanding-by-imitation.html</feedburner:origLink></entry>
 
 <entry>
   <title>Blogging is not easy!</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/zDpnpKR5VY8/thats-hard-to-write-a-blog.html" />
   <updated>2006-10-31T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/31/thats-hard-to-write-a-blog</id>
   <content type="html">
&lt;ul&gt;
	&lt;li&gt;my English is so clumsy! (is "clumsy" the good adjective to express how bad it is?)&lt;/li&gt;
	&lt;li&gt;my posts are too long to express any clear idea&lt;/li&gt;
	&lt;li&gt;there is still no code!!!&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/zDpnpKR5VY8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/31/thats-hard-to-write-a-blog.html</feedburner:origLink></entry>
 
 <entry>
   <title>@home</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/BqyLsIVBXRU/home.html" />
   <updated>2006-10-31T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/31/home</id>
   <content type="html">I recently discovered &lt;a href="http://africa-at-home.web.cern.ch/africa%2Dat%2Dhome/" title="Africa@Home" target="blank_"&gt;Africa@Home&lt;/a&gt;.&lt;br/&gt;
From of software engineer point of view, "@home" projects are very interesting. And when they are used for humanitarian purpose, that's even better, isn't it?&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/BqyLsIVBXRU" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/31/home.html</feedburner:origLink></entry>
 
 <entry>
   <title>From how to what</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/4m6G0xyQb8s/from-how-to-what.html" />
   <updated>2006-10-31T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/31/from-how-to-what</id>
   <content type="html">   Some of my good friends liked to kid me this way: they show me a program they just wrote/discover and secretly bid if I will ask my favorite question: "do you really need this?" [1]. Before they told me this fact, I didn't realized that I often ask that question. The bad thing is that it could sounds like "what useless is your work!" ... I'm so sorry if some people understood that of me. The good thing is that now I take care not to say it again ... but I keep remind the real meaning: what is the point which is really important in that? In fact the real question is not about the word "need", but is about the word "this".&lt;br/&gt;
To my mind, the real importance of this question is about distinguish "how" and "what" [2]: this point is useful for me in any area but let illustrate it with programming language.&lt;br/&gt;
When I learned to program I often thought in a problem-solving approach: I searched how to solve the problem. Perhaps because of the language I used: C. This is a perfect example of language to express not what you want to do but to express what you have to do to get this result: this is exactly how to do (and you can even set the register of the microprocessor because you know exactly how to do to obtain your result ... and how the processor work, wow!). This is really efficient on nowadays machine ... but with new processor instruction sets and hopefully new processor architectures (x86 is not really the best one!), with also concurrency in its way to be widespread everywhere, the compilation of C code may result in less efficient running code that compilation of high level language. OK OK, some times a cast in void** is easier and more efficient than anything else, but I'm really curious of what Haskell compiler developers will be able to do.&lt;br/&gt;
Another approach of problem is to concentrate on definition of what we try to solve (problem-defining approach?). The idea is that if you know exactly the prototype of the C function to write and its documentation, 80% of the work is done. The best example I can think of is a logical programming language: prolog. Those kind of programming give you an reasoning engine to which you just have to give facts and rules: he will search for you the result you want. You have to define what you know and what you want, he knows how to do, really! It's so convenient to express complex reasoning system of AI.&lt;br/&gt;
More surprisingly (to me at least) another language which guides you to think about what you want is SQL. That's only after having written some fairly complex queries (like mathematical integration of probability distributions) that I realized that I was completely focus on the data I have and on the data I want, and no way I can define how to proceed in SQL!
Those languages can be seen as declarative languages: express your knowledge of what you want, let the engine do it for you.&lt;br/&gt;
Another kind of language can help to problem-defining approach: the functional languages. Because the way to write functional code is to think about what is entry of function and what is the output: the "how to do" is replaced by "what is this function" (for example you don't write how to loop, you call the function which solve the next problem after the first step (often recursion)). Main difference between logical and functional languages is the internal engine of logical system (backtracking) which enable in logical language to not make difference between the parameters of function and the return value: functional language let you define what is the result and what is the process (here the developer is happy) where you have to use (and tricks) the logical language process with languages like prolog.&lt;br/&gt;
All that to say that in most of the case a language focusing on defining data and their process should be more convenient to design robust solution to well defined problem. And so my next blog post will probably be on what is my next language (matz said it's good to learn one language every year!).&lt;br/&gt;
[1] PAF used to call it the "coquellienne question"
[2] Lot of those ideas come from my studies/past experience at ENIB/CERV&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/4m6G0xyQb8s" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/31/from-how-to-what.html</feedburner:origLink></entry>
 
 <entry>
   <title>Re-discovering my music</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/HiCSOpcm-64/re-discovering-my-music.html" />
   <updated>2006-10-22T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/22/re-discovering-my-music</id>
   <content type="html">I changed the sound system of my computer from the cheapest one to a new Sony branded but yet very simple one. After 7 months using the old stuff, I just re-discover my music. That's too good, and &lt;a href="http://www.popachubby.com/home.html" title="Popa Chubby"&gt;Popa Chubby&lt;/a&gt; guitar's  sounds better than ever!&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/HiCSOpcm-64" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/22/re-discovering-my-music.html</feedburner:origLink></entry>
 
 <entry>
   <title>CS in learning, learning of CS</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/zmJ9CA5JRI4/cs-in-learning-learning-of-cs.html" />
   <updated>2006-10-22T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/22/cs-in-learning-learning-of-cs</id>
   <content type="html">About education of CS and CS in education.&lt;br/&gt;
In the &lt;span style="font-style:italic;"&gt;President's letter&lt;/span&gt; of &lt;span style="font-style:italic;"&gt;Communications of the ACM&lt;/span&gt; [March 2006, Volume 49, Number 3] David A. Patterson explained how to "re-invigorate computer science curriculum", and request for evolution of computer science education. Briefly, improving CV is achieved by two general ideas. The first is "&lt;em&gt;Technological update&lt;/em&gt;": student should study and use tools (ex. Eclipse) as well as library (ex. JUnit) for homework, and also a focus should be given on study  of parallelism. The second way to improve CV is to make "&lt;em&gt;Course I would love to take&lt;/em&gt;": for example he cites the construction of own supercomputer through FPGA, but also participation to an open-source project.&lt;br/&gt;
The point of view is mainly oriented toward programmers. And I agree that programmer students must be confronted to industry's reality: they should have used during home-works a version-control system, followed any methodology ... which imply that teachers use those tools too: this is not always the case as they are often researchers and don't have the same needs as industrial do.&lt;br/&gt;
The education problem is not so  simple if we think that today programmer can be tomorrow solution architect. Where the programmer will be interested in the better version-control system, the architect will like to know more about deployment tools. The problem arises: taking time constraint into account, what are the best things to teach to please future programmer but also future manager?
IMHO "&lt;strong&gt;what&lt;/strong&gt;" we learn at school is not so important as "&lt;strong&gt;how&lt;/strong&gt;" we learn it (curiously, when I am programming I always focus on "what" I do instead of "how" I do it ... could be the next blog post).  How we learn is of course the way we learn it but also the context or environment in which we learn it. If I would easily link the way to learn to pedagogical problem (see also an interesting blog on &lt;a href="http://blog.ianbicking.org/nonlinear-learning-nonlinear-internet.html"&gt;Non linear learning, the non linear internet&lt;/a&gt;), "how" we learn is certainly always oriented towards the learner: what is his motivation? And I guess that the only common interest for all students but also teachers is the &lt;strong&gt;CS culture&lt;/strong&gt;: tools, languages, methodologies, communities, blogs, research ... Students look only for help/guide/mentor/model to develop their computational thinking; if the teacher is aware to be an entry-point to CS culture, students will learn the needed knowledge from any source: lecturer, books, internet or themselves! Motivation is good enough (see &lt;a href="http://arstechnica.com/news.ars/post/20061017-8005.html"&gt;Scientists call for government to help fund video game research&lt;/a&gt;), students will learn what they need. Ok, this is the optimistic point of view of education.&lt;strong&gt;
&lt;/strong&gt;&lt;br/&gt;
Lots of random thoughts ... I hoped that bloging would help me to organize that confused brain of me, but instead it help to put in it some more random thoughts! All those ideas come to me when I thought to the recruitment problem: how to evaluate knowledge and knowledge use of a candidate? how to define the need of a position? ... still have so few ideas about it.&lt;br/&gt;
So I conclude with the only thought that is clear to me:
&lt;a href="http://khigia.files.wordpress.com/2006/10/smartedu.jpg" title="Education"&gt;
&lt;p style="text-align:center;"&gt;&lt;img src="http://khigia.files.wordpress.com/2006/10/smartedu.thumbnail.jpg" alt="Education" /&gt;&lt;/p&gt;&lt;br/&gt;
&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/zmJ9CA5JRI4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/22/cs-in-learning-learning-of-cs.html</feedburner:origLink></entry>
 
 <entry>
   <title>Education</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/-tXHOISvePM/education.html" />
   <updated>2006-10-22T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/22/education</id>
   <content type="html">&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/-tXHOISvePM" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/22/education.html</feedburner:origLink></entry>
 
 <entry>
   <title>MacMillan English Dictionary</title>
   <link href="http://feedproxy.google.com/~r/khigia/blog/~3/NajZqNviCt0/macmillan-english-dictionary.html" />
   <updated>2006-10-21T00:00:00+08:00</updated>
   <id>/wp-import/general/2006/10/21/macmillan-english-dictionary</id>
   <content type="html"> This is my first blog: hopefully I will make progress in writing after a while ... please be patient ;)&lt;br/&gt;
This is also my first English writing: I mean first text willingly written in English just for fun. We'll see if the spell checker is good. Making this blog will certainly encourage me to use my new &lt;a href="http://www.macmillandictionary.com//aboutonline.htm" title="about MacMillan dictiorany online version"&gt;MacMillan dictionary&lt;/a&gt;   for English learners: easy to search, easy to read with highlight of very common words (the "must know"), and easy to understand with very simple definitions. Particularity of this dictionary is that all the definitions are given using only a very small subset of English words, which is called the base vocabulary. I purchase the book version and got in same time free access to the on line version, which is really good and have the wonderful advantage of giving pronunciation by sound media.&lt;img src="http://feeds.feedburner.com/~r/khigia/blog/~4/NajZqNviCt0" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://blog.khigia.net//wp-import/general/2006/10/21/macmillan-english-dictionary.html</feedburner:origLink></entry>
 
 
</feed>
