<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>I do robots</title>
	<atom:link href="http://idorobots.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://idorobots.org</link>
	<description></description>
	<lastBuildDate>Sat, 04 May 2013 15:43:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='idorobots.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/ccce2eee4f7878fbde335bc5d455c40e?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>I do robots</title>
		<link>http://idorobots.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://idorobots.org/osd.xml" title="I do robots" />
	<atom:link rel='hub' href='http://idorobots.org/?pushpress=hub'/>
		<item>
		<title>Google Reader alternative for Emacs Ninjas</title>
		<link>http://idorobots.org/2013/03/30/greader-alternative/</link>
		<comments>http://idorobots.org/2013/03/30/greader-alternative/#comments</comments>
		<pubDate>Sat, 30 Mar 2013 22:37:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Emacs Lisp]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[Google Reader]]></category>
		<category><![CDATA[Google Reader alternative]]></category>
		<category><![CDATA[News reader]]></category>
		<category><![CDATA[Newsticker]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[RSS reader]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=2169</guid>
		<description><![CDATA[With Google Reader being discontinued and everyone looking for alternatives I&#8217;ve decided to look for a little less &#8220;standard&#8221; solution, and hey, it turns out Emacs can be a pretty powerful RSS reader. Newsticker.el News Ticker is a built-in Emacs feed reader that doesn&#8217;t get much attention for some reason. It is feature-rich, handles both [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=2169&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>With Google Reader being discontinued and everyone looking for alternatives I&#8217;ve decided to look for a little less <a href="http://www.feedly.com/">&#8220;standard&#8221;</a> solution, and hey, it turns out <b>Emacs</b> can be a pretty powerful RSS reader.
</p>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Newsticker.el</h2>
<div class="outline-text-2" id="text-1">
<p><a href="http://www.emacswiki.org/emacs/NewsTicker">News Ticker</a> is a built-in Emacs feed reader that doesn&#8217;t get much attention for some reason. It is feature-rich, handles both RSS 2.0 and Atom feeds and has <a href="http://www.gnu.org/software/emacs/manual/html_node/newsticker/Configuration.html#Configuration">quite a bunch of tweakable options</a>.<br />
Here&#8217;s a simple setup to start with:
</p>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">newsticker</span>)

<span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">W3M</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">HTML</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">renderer</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">isn't</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">essential,</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">but</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">it's</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">pretty</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">useful.</span>
(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">w3m</span>)
(setq<span style="color:#a9a9a9;"> </span>newsticker-html-renderer<span style="color:#a9a9a9;"> </span>'w3m-region)

<span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">We</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">want</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">our</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">feeds</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">pulled</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">every</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">10</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">minutes.</span>
(setq<span style="color:#a9a9a9;"> </span>newsticker-retrieval-interval<span style="color:#a9a9a9;"> </span>600)

<span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Setup</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">the</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">feeds.</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">We'll</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">have</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">look</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">at</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">these</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">in</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">just</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">second.</span>
(setq<span style="color:#a9a9a9;"> </span>newsticker-url-list-defaults<span style="color:#a9a9a9;"> </span>nil)
(setq<span style="color:#a9a9a9;"> </span>newsticker-url-list<span style="color:#a9a9a9;"> </span>'(<span style="color:#ffef6b;font-style:italic;">"..."</span>))

<span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Optionally</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">bind</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">shortcut</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">for</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">your</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">new</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">RSS</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">reader.</span>
(global-set-key<span style="color:#a9a9a9;"> </span>(kbd<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"C-c</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">r"</span>)<span style="color:#a9a9a9;"> </span>'newsticker-treeview)

<span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Don't</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">forget</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">to</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">start</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">it!</span>
(newsticker-start)
</pre>
<p><span id="more-2169"></span>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Migration</h2>
<div class="outline-text-2" id="text-2">
<p>First of all, you have to export your Google Reader data; you can do this <a href="https://www.google.com/takeout/?pli=1#custom:reader">here</a> by following <a href="http://webapps.stackexchange.com/questions/41602/can-i-download-all-my-data-from-google-reader/41604#41604">these</a> instructions. Download and unzip it into a safe location.<br />
Now, all you will need to migrate from Google Reader to News Ticker is <a href="https://gist.github.com/Idorobots/5278294">this little piece of code</a>:
</p>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">xml</span>)

(<span style="color:#729fcf;font-weight:bold;">defun</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">assoc-or-error</span><span style="color:#a9a9a9;"> </span>(what<span style="color:#a9a9a9;"> </span>where<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">&amp;optional</span><span style="color:#a9a9a9;"> </span>err-string)
<span style="color:#a9a9a9;">  </span>(or<span style="color:#a9a9a9;"> </span>(assoc<span style="color:#a9a9a9;"> </span>what<span style="color:#a9a9a9;"> </span>where)
<span style="color:#a9a9a9;">      </span>(<span style="color:#f50c00;font-weight:bold;">error</span><span style="color:#a9a9a9;"> </span>(or<span style="color:#a9a9a9;"> </span>err-string
<span style="color:#a9a9a9;">                 </span><span style="color:#ffef6b;font-style:italic;">"Suddenly</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">errors!</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Thousands</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">of</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">them!"</span>))))

(<span style="color:#729fcf;font-weight:bold;">defun</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">google-reader-to-newsticker</span><span style="color:#a9a9a9;"> </span>(filename)
<span style="color:#a9a9a9;">  </span><span style="color:#757a9a;font-weight:bold;">"Parses</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">your</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">google-reader</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">subscription</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">XML</span>
<span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">and</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">returns</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">newsticker</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">compatible</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#757a9a;font-weight:bold;">alist."</span>
<span style="color:#a9a9a9;">  </span>(<span style="color:#729fcf;font-weight:bold;">with-temp-buffer</span>
<span style="color:#a9a9a9;">    </span>(insert-file-contents<span style="color:#a9a9a9;"> </span>filename)
<span style="color:#a9a9a9;">    </span>(<span style="color:#729fcf;font-weight:bold;">let*</span><span style="color:#a9a9a9;"> </span>((opml<span style="color:#a9a9a9;"> </span>(assoc-or-error
<span style="color:#a9a9a9;">                  </span>'opml
<span style="color:#a9a9a9;">                  </span>(xml-parse-region<span style="color:#a9a9a9;"> </span>(point-min)
<span style="color:#a9a9a9;">                                    </span>(point-max))
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">"Not</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">valid</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">XML!"</span>))
<span style="color:#a9a9a9;">           </span>(body<span style="color:#a9a9a9;"> </span>(assoc-or-error
<span style="color:#a9a9a9;">                  </span>'body
<span style="color:#a9a9a9;">                  </span>opml
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">"Not</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">valid</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">XML!"</span>))
<span style="color:#a9a9a9;">           </span>(outlines<span style="color:#a9a9a9;"> </span>(delq<span style="color:#a9a9a9;"> </span>nil
<span style="color:#a9a9a9;">                           </span>(map<span style="color:#a9a9a9;"> </span>'list
<span style="color:#a9a9a9;">                                </span>(<span style="color:#729fcf;font-weight:bold;">lambda</span><span style="color:#a9a9a9;"> </span>(element)
<span style="color:#a9a9a9;">                                  </span>(and<span style="color:#a9a9a9;"> </span>(consp<span style="color:#a9a9a9;"> </span>element)
<span style="color:#a9a9a9;">                                       </span>(equal<span style="color:#a9a9a9;"> </span>(car<span style="color:#a9a9a9;"> </span>element)
<span style="color:#a9a9a9;">                                              </span>'outline)
<span style="color:#a9a9a9;">                                       </span>element))
<span style="color:#a9a9a9;">                                </span>body)))
<span style="color:#a9a9a9;">           </span>(alist
<span style="color:#a9a9a9;">            </span>(map<span style="color:#a9a9a9;"> </span>'list
<span style="color:#a9a9a9;">                 </span>(<span style="color:#729fcf;font-weight:bold;">lambda</span><span style="color:#a9a9a9;"> </span>(outline)
<span style="color:#a9a9a9;">                   </span>(<span style="color:#729fcf;font-weight:bold;">let</span><span style="color:#a9a9a9;"> </span>((title<span style="color:#a9a9a9;"> </span>(assoc-or-error
<span style="color:#a9a9a9;">                                 </span>'title
<span style="color:#a9a9a9;">                                 </span>outline
<span style="color:#a9a9a9;">                                 </span>(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"No</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">title</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">in</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">an</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">outline</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>
<span style="color:#a9a9a9;">                                         </span><span style="color:#ffef6b;font-style:italic;">"-</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">malformed</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">XML?"</span>))
<span style="color:#a9a9a9;">                         </span>(feed<span style="color:#a9a9a9;"> </span>(assoc-or-error
<span style="color:#a9a9a9;">                                </span>'xmlUrl
<span style="color:#a9a9a9;">                                </span>outline
<span style="color:#a9a9a9;">                                </span>(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"No</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">link</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">in</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">an</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">outline</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>
<span style="color:#a9a9a9;">                                        </span>'<span style="color:#ffef6b;font-style:italic;">"-</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">check</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">your</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">feed</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">XML!"</span>)))
<span style="color:#a9a9a9;">                     </span>(list<span style="color:#a9a9a9;"> </span>(cdr<span style="color:#a9a9a9;"> </span>title)<span style="color:#a9a9a9;"> </span>(cdr<span style="color:#a9a9a9;"> </span>feed))))
<span style="color:#a9a9a9;">                 </span>(map<span style="color:#a9a9a9;"> </span>'list
<span style="color:#a9a9a9;">                      </span>#'cadr
<span style="color:#a9a9a9;">                      </span>outlines))))
<span style="color:#a9a9a9;">      </span>alist)))
</pre>
<p>
Simply <code>eval</code> it in your Emacs and run the following lines to import all your Google Reader feeds directly to News Ticker.
</p>
<pre class="src src-emacs-lisp">(setq<span style="color:#a9a9a9;"> </span>newsticker-url-list
<span style="color:#a9a9a9;">  </span>(google-reader-to-newsticker<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"/path/to/subscriptions.xml"</span>))
</pre>
<p>
You might want to save your feeds for later via <b>Newsticker Url List</b> setting under:
</p>
<pre class="example">
M-x customize-group newsticker-retrieval
</pre>
<p>
As with anything Emacs, you can bend News Ticker to your will and make it do whatever you please. Depending on your Emacs theme it might look something like this:
</p>
<p><a href="http://idorobots.files.wordpress.com/2013/03/wpid-feeds.png"></p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2013/03/wpid-feeds.png?w=549" alt="http://idorobots.files.wordpress.com/2013/03/wpid-feeds.png?w=549" />
</p>
</div>
<p></a></p>
<p>
Go ahead, <a href="http://media.tumblr.com/tumblr_m39honikF01r9nrs0.png">customize all the things!</a>
</p>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Extra ninja</h2>
<div class="outline-text-2" id="text-3">
<p>If you, like me, read loads of feeds every day you might consider adding a tiny notification <i>thing-a-ma-jigger</i> to your Emacs <code>mode-line</code>, just place the following code in your custom <code>mode-line-format</code>&hellip;
</p>
<pre class="src src-emacs-lisp">(setq-default<span style="color:#a9a9a9;"> </span>mode-line-format
<span style="color:#a9a9a9;">  </span>(list
<span style="color:#a9a9a9;">    </span><span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>

<span style="color:#a9a9a9;">    </span>'(<span style="color:#729fcf;">:eval</span><span style="color:#a9a9a9;"> </span>(<span style="color:#729fcf;font-weight:bold;">let</span><span style="color:#a9a9a9;"> </span>((unread<span style="color:#a9a9a9;"> </span>(or<span style="color:#a9a9a9;"> </span>(newsticker--stat-num-items-total<span style="color:#a9a9a9;"> </span>'new)
<span style="color:#a9a9a9;">                              </span>0)))
<span style="color:#a9a9a9;">              </span>(<span style="color:#729fcf;font-weight:bold;">when</span><span style="color:#a9a9a9;"> </span>(&gt;<span style="color:#a9a9a9;"> </span>unread<span style="color:#a9a9a9;"> </span>0)
<span style="color:#a9a9a9;">                </span>(propertize
<span style="color:#a9a9a9;">                  </span><span style="color:#888a85;">;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Any</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">text</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">will</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">do,</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">be</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">creative!</span>
<span style="color:#a9a9a9;">                  </span>(format<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"RSS:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%d"</span><span style="color:#a9a9a9;"> </span>unread)
<span style="color:#a9a9a9;">                  </span>'face<span style="color:#a9a9a9;"> </span>'some-colorful-font-face
<span style="color:#a9a9a9;">                  </span>'help-echo<span style="color:#a9a9a9;"> </span>(format<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"You</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">have</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%d</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">unread</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">RSS</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">items!"</span>
<span style="color:#a9a9a9;">                                     </span>unread)
<span style="color:#a9a9a9;">                  </span>'mouse-face<span style="color:#a9a9a9;"> </span>'mode-line-highlight))))))
</pre>
<p>
&hellip;and enjoy it popping into existence every now and then (note the use of awesome <a href="http://fortawesome.github.com/Font-Awesome/">Font Awesome</a>):
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2013/03/wpid-1unread.png?w=549" alt="http://idorobots.files.wordpress.com/2013/03/wpid-1unread.png?w=549" /><br />
Happy procrastinating!
</p>
</div>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/2169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/2169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=2169&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2013/03/30/greader-alternative/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/03/wpid-feeds.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2013/03/wpid-feeds.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/03/wpid-1unread.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2013/03/wpid-1unread.png</media:title>
		</media:content>
	</item>
		<item>
		<title>MMO Life</title>
		<link>http://idorobots.org/2013/02/02/mmo-life/</link>
		<comments>http://idorobots.org/2013/02/02/mmo-life/#comments</comments>
		<pubDate>Sat, 02 Feb 2013 22:59:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[dot]]></category>
		<category><![CDATA[gamification]]></category>
		<category><![CDATA[gamify]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[Graphviz]]></category>
		<category><![CDATA[org-mode]]></category>
		<category><![CDATA[skills]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=2089</guid>
		<description><![CDATA[This is a follow-up post to Gamification showing how I use it and what purpose does it serve me. In summary, I&#8217;m a kind of control freak who likes all sorts of stats (such as my systems stats or a projects repo stats) displayed neatly all over the place, and it was only a matter [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=2089&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is a follow-up post to <a href="http://idorobots.org/2012/12/07/gamification/">Gamification</a> showing how I use it and what purpose does it serve me.
</p>
<p>
In summary, I&#8217;m a kind of control freak who <a href="http://fc01.deviantart.net/fs70/f/2012/044/0/4/me_gusta_plain_by_starchynicky-d4pl74q.png">likes</a> all sorts of stats (such as <a href="http://idorobots.org/2012/10/10/emacs-mode-line/">my systems stats</a> or <a href="https://github.com/Idorobots">a projects repo</a> stats) displayed neatly all over the place, and it was only a matter of time before I started monitoring <i>myself</i>, and so I wrote a tiny tool, <a href="https://github.com/Idorobots/gamify-el">Gamify</a>, that integrates with Emacs&#8217; Org-Mode and tracks my skills, their dependencies and their development.
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2013/02/wpid-programming.png?w=549" title="Welcome to the Shameless Self-plug City, where the graphs are green and the girls are... Well, absent..." alt="http://idorobots.files.wordpress.com/2013/02/wpid-programming.png?w=549" />
</p>
</div>
<p><span id="more-2089"></span></p>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Endless adventure</h2>
<div class="outline-text-2" id="text-1">
<p>Gamify collects experience points associated with Org-Mode tasks whenever I complete them. Each task can be tagged with any number of <i>skills</i> (Org&#8217;s tag inheritance is very handy here) and assigned some <i>XP</i>, preferably using <code>gamify-assign-some-exp</code>:
</p>
<pre class="src src-org"><span style="color:#edd400;font-weight:bold;font-style:italic;">*</span><span style="color:#a9a9a9;"> </span><span style="color:#ffc0cb;font-weight:bold;">TODO</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Write</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">follow-up</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">post</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">about</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Gamify.</span><span style="color:#a9a9a9;">                 </span><span style="color:#edd400;font-weight:bold;font-style:italic;">:Blogging:</span>
<span style="color:#729fcf;font-weight:bold;">SCHEDULED:</span><span style="color:#a9a9a9;"> </span><span style="color:#00ffff;text-decoration:underline;">&lt;2013-02-02</span><span style="color:#a9a9a9;"> </span><span style="color:#00ffff;text-decoration:underline;">sat&gt;</span>
<span style="color:#729fcf;font-weight:bold;">:PROPERTIES:</span>
<span style="color:#729fcf;font-weight:bold;">:gamify_exp:</span><span style="color:#a9a9a9;"> </span>20
<span style="color:#729fcf;font-weight:bold;">:END:</span>

When<span style="color:#a9a9a9;"> </span>I<span style="color:#a9a9a9;"> </span>complete<span style="color:#a9a9a9;"> </span>this<span style="color:#a9a9a9;"> </span>task<span style="color:#a9a9a9;"> </span>by<span style="color:#a9a9a9;"> </span>changing<span style="color:#a9a9a9;"> </span>its<span style="color:#a9a9a9;"> </span>state<span style="color:#a9a9a9;"> </span>to<span style="color:#a9a9a9;"> </span><span style="font-weight:bold;">*DONE*</span>
Gamify<span style="color:#a9a9a9;"> </span>will<span style="color:#a9a9a9;"> </span>take<span style="color:#a9a9a9;"> </span>care<span style="color:#a9a9a9;"> </span>of<span style="color:#a9a9a9;"> </span>updating<span style="color:#a9a9a9;"> </span>my<span style="color:#a9a9a9;"> </span><span style="font-style:italic;">/Blogging/</span><span style="color:#a9a9a9;"> </span>skill.
</pre>
<p>
As every Gamify-enabled task is assigned an arbitrary XP some calibration of skill-levels was needed. I&#8217;ve settled for a slightly modified version of <a href="http://dwarffortresswiki.org/index.php/DF2012:Skill">DF level names</a> (because I&#8217;m nerdy like that) and an exponential effort growth:
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2013/02/wpid-plot1.png?w=549" title="Tesla should be a valid skill level everywhere. Tesla is awesome." alt="http://idorobots.files.wordpress.com/2013/02/wpid-plot1.png?w=549" />
</p>
</div>
<p>
It takes roughly 4 years of daily skill training (6 tasks 12 XP each on average) to get a hold at a skill and become <i>Professional</i>, 20 years to become a <i>Legendary</i> hacker and <b>63 years</b> to become <a href="http://modowo.pl/uploads/assets/kultura/publicystyka/nikola-tesla-wireless-electricity.jpg">Tesla</a>.
</p>
<p>
Naturally, to be any useful Gamify has to provide lot&#8217;s of feedback which it does either in textual form using <code>gamify-get-pretty-stats</code>:
</p>
<pre class="example">Your Gamify stats:
Competent at Blogging: 3836/8500 (2%)
Competent at C++: 8144/8500 (92%)
Proficient at CodeDev: 23805/28900 (58%)
Competent at Concurrency: 4129/8500 (8%)
Competent at D: 5522/8500 (37%)
Competent at Editing: 5283/8500 (32%)
Competent at Emacs: 4994/8500 (26%)
Skilled at Functional Programming: 8829/16600 (4%)
Competent at GameDev: 6104/8500 (50%)
Skilled at Imperative Programming: 16092/16600 (93%)
Competent at Lisp: 5523/8500 (37%)
Skilled at OOP: 9323/16600 (10%)
Competent at Project Management: 3963/8500 (5%)
Proficient at Programming: 19490/28900 (23%)
Competent at Robotics: 6884/8500 (66%)
Competent at Software Engineering: 3700/8500 (0%)
</pre>
<p>
&hellip;or using <a href="http://www.graphviz.org/">Graphviz</a> for graph visualization.
</p>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Some more examples</h2>
<div class="outline-text-2" id="text-2">
<p>In a nutshell, this is <i>me</i>:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-all.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-all.png?w=549" title="It's a me, nerdling!" alt="http://idorobots.files.wordpress.com/2013/02/wpid-all.png?w=549" /><br />
</a>
</p>
</div>
<p>
Well, to be honest most of the skills I&#8217;m novice or dabbling at don&#8217;t belong in my <i>defining skill-set</i>, so more like this is me:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-adequate.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-adequate.png?w=549" title="Adequate and above." alt="http://idorobots.files.wordpress.com/2013/02/wpid-adequate.png?w=549" /><br />
</a>
</p>
</div>
<p>
&hellip;and this is what I&#8217;m good at:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-skilled.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-skilled.png?w=549" title="Took me a bit longer than the above plot might suggest." alt="http://idorobots.files.wordpress.com/2013/02/wpid-skilled.png?w=549" /><br />
</a>
</p>
</div>
<p>
Additionally, Gamify monitors my interests&hellip;
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-gd.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-gd.png?w=549" title="We all like games, don't we?" alt="http://idorobots.files.wordpress.com/2013/02/wpid-gd.png?w=549" /><br />
</a>
</p>
</div>
<p>
&hellip;and how they interact with each other:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-robogd.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-robogd.png?w=549" title="...and robots. I do robots, after all, right? Guys? Anyone?" alt="http://idorobots.files.wordpress.com/2013/02/wpid-robogd.png?w=549" /><br />
</a>
</p>
</div>
<p>
But most importantly, it helps me estimate whether I&#8217;m qualified for a particular task or not.<br />
Say, you want me to build an Operating System in <a href="http://dlang.org">D</a>. All I need to do is filter my skill-set by <i>D</i> and <i>OSDev</i>, yielding a bunch of relevant info:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-osd.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-osd.png?w=549" title="Bad idea..." alt="http://idorobots.files.wordpress.com/2013/02/wpid-osd.png?w=549" /><br />
</a>
</p>
</div>
<p>
I mean I did write a toy kernel in D that does absolutely nothing, <a href="http://images.wikia.com/uncyclopedia/images/1/16/Coolface.png">so&hellip; Yeah&hellip;</a>
</p>
<p>
Anyway, say, you want me to help develop an OS&hellip; In Lisp&hellip; <a href="http://lispjobs.wordpress.com/2012/10/16/ai-software-developer-zenrobotics-helsinki/">For your robots</a>:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2013/02/wpid-oslisprobo.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2013/02/wpid-oslisprobo.png?w=549" title="This is actually one of my goals." alt="http://idorobots.files.wordpress.com/2013/02/wpid-oslisprobo.png?w=549" /><br />
</a>
</p>
</div>
<p>
I may not be particularly well-suited for this job right away, but I immediately see lot&#8217;s of room for self-improvement. I could, for example, take an <a href="http://en.wikipedia.org/wiki/Machine_learning">ML</a> course or two and start a toy robotics project for fun and profit, and who knows, maybe in five years <a href="http://i50.tinypic.com/213ktjb.png">I&#8217;ll fit just right</a>.
</p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/2089/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/2089/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=2089&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2013/02/02/mmo-life/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-programming.png" medium="image">
			<media:title type="html">Welcome to the Shameless Self-plug City, where the graphs are green and the girls are... Well, absent...</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-plot1.png" medium="image">
			<media:title type="html">Tesla should be a valid skill level everywhere. Tesla is awesome.</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-all.png" medium="image">
			<media:title type="html">It&#039;s a me, nerdling!</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-adequate.png" medium="image">
			<media:title type="html">Adequate and above.</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-skilled.png" medium="image">
			<media:title type="html">Took me a bit longer than the above plot might suggest.</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-gd.png" medium="image">
			<media:title type="html">We all like games, don&#039;t we?</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-robogd.png" medium="image">
			<media:title type="html">...and robots. I do robots, after all, right? Guys? Anyone?</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-osd.png" medium="image">
			<media:title type="html">Bad idea...</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/02/wpid-oslisprobo.png" medium="image">
			<media:title type="html">This is actually one of my goals.</media:title>
		</media:content>
	</item>
		<item>
		<title>ASM development log 4: Tiny MOP</title>
		<link>http://idorobots.org/2013/01/19/asm-dev-log-4/</link>
		<comments>http://idorobots.org/2013/01/19/asm-dev-log-4/#comments</comments>
		<pubDate>Sat, 19 Jan 2013 17:00:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[ASM]]></category>
		<category><![CDATA[ASM log]]></category>
		<category><![CDATA[CLOS]]></category>
		<category><![CDATA[Meta Object Protocol]]></category>
		<category><![CDATA[MOP]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[TinyCLOS]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=2048</guid>
		<description><![CDATA[Finals are comming, so I might as well hack around a bit with ASM&#8230; It&#8217;s been a while since the last status update and I hate to admit it, but not much has changed in ASM repo. I was messing around with combinators in an attempt to simplify ASM&#8217; environments, and I was experimenting with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=2048&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://weknowmemes.com/wp-content/uploads/2012/05/studying-for-finals.jpg">Finals are comming</a>, so I might as well hack around a bit with <b>ASM</b>&hellip;<br />
<a href="http://idorobots.org/asm" target="_blank"><img src="http://idorobots.files.wordpress.com/2013/01/mop.png?w=549" alt="" class="alignright" /></a><br />
It&#8217;s been a while since <a href="http://idorobots.org/2012/08/17/asm-dev-log-3/">the last status update</a> and I hate to admit it, but not much has changed in <a href="http://code.google.com/p/asm-programming-language/">ASM repo</a>. I was messing around with <a href="http://en.wikipedia.org/wiki/Combinatory_logic">combinators</a> in an attempt to simplify ASM&#8217; environments, and I was experimenting with new immutability semantics, since at the moment it&#8217;s pretty much a one big copy-vs-alias mess. There are still a bunch of unresolved issues here and there concerning efficiency mainly, but if ASM is to be relevant in <a href="http://paulgraham.com/hundred.html">100 years of time</a> I&#8217;d much rather sacrifice efficiency for simpler semantics and expressive power.<br />
Lastly, I was thinking about a way of exposing as much of ASM&#8217; semantics as possible and allowing their run-time overriding, using a <a href="http://en.wikipedia.org/wiki/Metaobject">Metaobject protocol</a>:
</p>
<pre class="src src-common-lisp">(<span style="color:#729fcf;font-weight:bold;">import</span><span style="color:#a9a9a9;"> </span>'samples.tinyclos)

(<span style="color:#729fcf;font-weight:bold;">defmethod</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">apply</span><span style="color:#a9a9a9;"> </span>((v<span style="color:#a9a9a9;"> </span>Vector)<span style="color:#a9a9a9;"> </span>n)
<span style="color:#a9a9a9;">  </span>(write<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Applying</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">vector</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">to</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">something?</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Are</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">you</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span><span style="color:#a9a9a9;"> </span>n<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"?"</span>))

(apply<span style="color:#a9a9a9;"> </span>'[1<span style="color:#a9a9a9;"> </span>2<span style="color:#a9a9a9;"> </span>3<span style="color:#a9a9a9;"> </span>4]<span style="color:#a9a9a9;"> </span>'(nuts))
</pre>
<p><span id="more-2048"></span></p>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">TinyCLOS</h2>
<div class="outline-text-2" id="text-1">
<p><a href="http://community.schemewiki.org/?Tiny-CLOS">TinyCLOS</a> is an object system that includes a metaobject protocol developed by Gregor Kiczales at Xerox for the Scheme programming language. It&#8217;s relatively simple yet immensely powerful and <a href="http://code.google.com/p/asm-programming-language/source/browse/samples/tinyclos.asm">porting it to ASM</a> was both great fun and a nice test for the capabilities of the language. Running rather slowly as ASM&#8217;s testing interpreter is very cons-and-copy-happy it continues to amuse me even with its basic features such as <a href="http://en.wikipedia.org/wiki/Multiple_dispatch">generic methods with multiple dispatch</a>:
</p>
<pre class="src src-common-lisp">(<span style="color:#729fcf;font-weight:bold;">import</span><span style="color:#a9a9a9;"> </span>'samples.tinyclos)

(<span style="color:#729fcf;font-weight:bold;">defclass</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Point</span><span style="color:#a9a9a9;"> </span>(Object)
<span style="color:#a9a9a9;">  </span>'x<span style="color:#a9a9a9;"> </span>'y)

(<span style="color:#729fcf;font-weight:bold;">defmethod</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">initialize</span><span style="color:#a9a9a9;"> </span>((p<span style="color:#a9a9a9;"> </span>Point)<span style="color:#a9a9a9;"> </span>initargs)
<span style="color:#a9a9a9;">  </span>(call-next-method)
<span style="color:#a9a9a9;">  </span>(initialize-slots<span style="color:#a9a9a9;"> </span>p<span style="color:#a9a9a9;"> </span>initargs))

(<span style="color:#729fcf;font-weight:bold;">defclass</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Point3D</span><span style="color:#a9a9a9;"> </span>(Point)
<span style="color:#a9a9a9;">  </span>'z)

(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">p1</span><span style="color:#a9a9a9;"> </span>(new<span style="color:#a9a9a9;"> </span>Point<span style="color:#a9a9a9;"> </span>'x<span style="color:#a9a9a9;"> </span>1<span style="color:#a9a9a9;"> </span>'y<span style="color:#a9a9a9;"> </span>2))
(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">p2</span><span style="color:#a9a9a9;"> </span>(new<span style="color:#a9a9a9;"> </span>Point<span style="color:#a9a9a9;"> </span>'x<span style="color:#a9a9a9;"> </span>2<span style="color:#a9a9a9;"> </span>'y<span style="color:#a9a9a9;"> </span>3))
(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">p3</span><span style="color:#a9a9a9;"> </span>(new<span style="color:#a9a9a9;"> </span>Point3D<span style="color:#a9a9a9;"> </span>'x<span style="color:#a9a9a9;"> </span>5<span style="color:#a9a9a9;"> </span>'y<span style="color:#a9a9a9;"> </span>5<span style="color:#a9a9a9;"> </span>'z<span style="color:#a9a9a9;"> </span>5))

(<span style="color:#729fcf;font-weight:bold;">defgeneric</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">distance</span>)
(<span style="color:#729fcf;font-weight:bold;">defmethod</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">distance</span><span style="color:#a9a9a9;"> </span>((a<span style="color:#a9a9a9;"> </span>Point)<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>Point))
<span style="color:#a9a9a9;">  </span>(write<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Point</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">*</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Point\n"</span>)
<span style="color:#a9a9a9;">  </span>(distance<span style="color:#a9a9a9;"> </span>(new<span style="color:#a9a9a9;"> </span>Point3D<span style="color:#a9a9a9;"> </span>'x<span style="color:#a9a9a9;"> </span>(a<span style="color:#a9a9a9;"> </span>'x)<span style="color:#a9a9a9;"> </span>'y<span style="color:#a9a9a9;"> </span>(a<span style="color:#a9a9a9;"> </span>'y)<span style="color:#a9a9a9;"> </span>'z<span style="color:#a9a9a9;"> </span>0)
<span style="color:#a9a9a9;">            </span>(new<span style="color:#a9a9a9;"> </span>Point3D<span style="color:#a9a9a9;"> </span>'x<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'x)<span style="color:#a9a9a9;"> </span>'y<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'y)<span style="color:#a9a9a9;"> </span>'z<span style="color:#a9a9a9;"> </span>0)))

(<span style="color:#729fcf;font-weight:bold;">defmethod</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">distance</span><span style="color:#a9a9a9;"> </span>((a<span style="color:#a9a9a9;"> </span>Point)<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>Point3D))
<span style="color:#a9a9a9;">  </span>(write<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Point</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">*</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Point3D\n"</span>)
<span style="color:#a9a9a9;">  </span>(distance<span style="color:#a9a9a9;"> </span>b<span style="color:#a9a9a9;"> </span>a))

(<span style="color:#729fcf;font-weight:bold;">defmethod</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">distance</span><span style="color:#a9a9a9;"> </span>((a<span style="color:#a9a9a9;"> </span>Point3D)<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>Point))
<span style="color:#a9a9a9;">  </span>(write<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Point3D</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">*</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Point\n"</span>)
<span style="color:#a9a9a9;">  </span>(distance<span style="color:#a9a9a9;"> </span>a<span style="color:#a9a9a9;"> </span>(new<span style="color:#a9a9a9;"> </span>Point3D<span style="color:#a9a9a9;"> </span>'x<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'x)<span style="color:#a9a9a9;"> </span>'y<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'y)<span style="color:#a9a9a9;"> </span>'z<span style="color:#a9a9a9;"> </span>0)))

(<span style="color:#729fcf;font-weight:bold;">defmethod</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">distance</span><span style="color:#a9a9a9;"> </span>((a<span style="color:#a9a9a9;"> </span>Point3D)<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>Point3D))
<span style="color:#a9a9a9;">  </span>(write<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Point3D</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">*</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Point3D\n"</span>)
<span style="color:#a9a9a9;">  </span>(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">dx</span><span style="color:#a9a9a9;"> </span>(-<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'x)<span style="color:#a9a9a9;"> </span>(a<span style="color:#a9a9a9;"> </span>'x)))
<span style="color:#a9a9a9;">  </span>(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">dy</span><span style="color:#a9a9a9;"> </span>(-<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'y)<span style="color:#a9a9a9;"> </span>(a<span style="color:#a9a9a9;"> </span>'y)))
<span style="color:#a9a9a9;">  </span>(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">dz</span><span style="color:#a9a9a9;"> </span>(-<span style="color:#a9a9a9;"> </span>(b<span style="color:#a9a9a9;"> </span>'z)<span style="color:#a9a9a9;"> </span>(a<span style="color:#a9a9a9;"> </span>'z)))
<span style="color:#a9a9a9;">  </span>(pow<span style="color:#a9a9a9;"> </span>(+<span style="color:#a9a9a9;"> </span>(*<span style="color:#a9a9a9;"> </span>dx<span style="color:#a9a9a9;"> </span>dx)<span style="color:#a9a9a9;"> </span>(*<span style="color:#a9a9a9;"> </span>dy<span style="color:#a9a9a9;"> </span>dy)<span style="color:#a9a9a9;"> </span>(*<span style="color:#a9a9a9;"> </span>dz<span style="color:#a9a9a9;"> </span>dz)<span style="color:#a9a9a9;"> </span>0.5)))

(distance<span style="color:#a9a9a9;"> </span>p1<span style="color:#a9a9a9;"> </span>p2)
(distance<span style="color:#a9a9a9;"> </span>p3<span style="color:#a9a9a9;"> </span>p1)
(distance<span style="color:#a9a9a9;"> </span>p2<span style="color:#a9a9a9;"> </span>p3)
(distance<span style="color:#a9a9a9;"> </span>p3<span style="color:#a9a9a9;"> </span>p3)

</pre>
<p>
Output:
</p>
<pre class="example">Point * Point
Point3D * Point3D
Point3D * Point
Point3D * Point3D
Point * Point3D
Point3D * Point
Point3D * Point3D
Point3D * Point3D
</pre>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">F(ea|u)ture?</h2>
<div class="outline-text-2" id="text-2">
<p>I once were an OOP enthusiast, but grew to hate it for <a href="http://www.geocities.com/tablizer/myths.htm">various reasons</a>. Most of all, I fell in love with functional programming and OOP (at least the Java-flavour) suddenly started looking clumsy and awkward. The world wasn&#8217;t made of objects anymore, it was made of <code>foldr</code> and <code>foldl</code> instead. Now, although I still don&#8217;t see ASM as an OOP-heavy language, I&#8217;m sure it&#8217;ll make some use of it &#8211; for example implementing <a href="http://www.informit.com/articles/article.aspx?p=1407357">ranges</a> with all their benefits comes naturally in an OOP-enabled language.<br />
Furthermore, to extend ASM&#8217;s expressiveness beyond what any other language has to offer I will need a <i>meta-language protocol</i> of sorts, perhaps Tiny MOP is a good start towards that&hellip;<br />
<a href="http://blog.antec.com/wp-content/uploads/2010/12/BorgCube1.jpg">Thing</a>&hellip;
</p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/2048/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/2048/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=2048&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2013/01/19/asm-dev-log-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2013/01/mop.png" medium="image" />
	</item>
		<item>
		<title>You earned 15 XP in Getting Things Done!</title>
		<link>http://idorobots.org/2012/12/07/gamification/</link>
		<comments>http://idorobots.org/2012/12/07/gamification/#comments</comments>
		<pubDate>Fri, 07 Dec 2012 18:00:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[gamification]]></category>
		<category><![CDATA[org-mode]]></category>
		<category><![CDATA[pomodoro]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1790</guid>
		<description><![CDATA[Gamification According to the Oxford Dictionary&#8230; Gamification (ˌɡeɪmɪfɪˈkeɪʃ(ə)n) is the application of typical elements of game playing (e.g. point scoring, competition with others, rules of play) to other areas of activity, typically as an online marketing technique to encourage engagement with a product or service: gamification is exciting because it promises to make the hard [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1790&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Gamification</h2>
<div class="outline-text-2" id="text-1">
<p>According to the <a href="http://oxforddictionaries.com/definition/english/gamification">Oxford Dictionary</a>&hellip;
</p>
<blockquote>
<p><b>Gamification</b> (ˌɡeɪmɪfɪˈkeɪʃ(ə)n) is the application of typical elements of game playing (e.g. point scoring, competition with others, rules of play) to other areas of activity, typically as an online marketing technique to encourage engagement with a product or service:<br />
gamification is exciting because it promises to make the hard stuff in life fun.
</p>
</blockquote>
<p>
Let&#8217;s see how to apply it to optimize performing daily activities and get some useful statistics out of it&hellip;
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2012/12/wpid-foo41.png?w=549" alt="http://idorobots.files.wordpress.com/2012/12/wpid-foo41.png?w=549" />
</p>
</div>
<p><span id="more-1790"></span></p>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Disregard contexts, acquire experience</h2>
<div class="outline-text-2" id="text-2">
<p>I use Emacs <a href="http://orgmode.org/">Org-Mode</a>, a plain text focused, organization powerhouse, to manage both my work and my private life implementing the <a href="http://members.optusnet.com.au/~charles57/GTD/gtd_workflow.html">Getting Things Done</a> techniques. And as far as Org-Mode goes it works like a charm, but there&#8217;s still <a href="https://i.chzbgr.com/completestore/12/7/10/8nnukHDQykmuLQH8UsCGCw2.jpg">the human factor</a>&hellip;
</p>
<p>
I hate to admit it, but I&#8217;m a slow-starter. Beginning some of the tasks, especially the seemingly harder ones, tends to be a problem for me and I usually need a considerable amount of preparation time beforehand, or an outside motivator of sorts, for example a milestone deadline or a course grade.
</p>
<p>
Staying focused on a performed task or keeping a task streak going has never been a real problem for me, and ever since I optimized it using the <a href="http://www.pomodorotechnique.com/">Pomodoro</a> technique it became apparent that most of my productivity loss comes about before beginning a Next Action &#8211; it takes me quite some time and effort to <b>actually start</b> a series of actions that make up a complex task when I&#8217;m not looking forward to doing them and there&#8217;s no real sense of urgency or reward. I just keep pushing the task back and back.
</p>
<p>
To overcome this recurring phenomenon I took a closer look at my GTD workflow &#8211; task contexts in particular.<br />
I used to tag my Org-Mode tasks based on the place they could be carried out and sometimes by their type, what looked something like this:
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2012/12/wpid-old1.png?w=549" alt="http://idorobots.files.wordpress.com/2012/12/wpid-old1.png?w=549" />
</p>
</div>
<p>
It turns out that such context tags are barely useful and carry little to none statistical value, and since I tend to keep all my working environments closely synchronized these contexts weren&#8217;t even valid half the time &#8211; the tasks could be performed in either context. This got me thinking and I decided to drop task contexts whatsoever in favour of something more useful&hellip;
</p>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Gamify.el</h2>
<div class="outline-text-2" id="text-3">
<p>&hellip;and fun. <a href="https://github.com/Idorobots/gamify-el">This Emacs package</a> is my attempt at doing so. It&#8217;ll help you keep track of your <code>stats</code> &#8211; any quantifiable values you name, be it your soft skills or your experience with various technologies and software. At its current state it&#8217;s mostly usable together with <a href="http://orgmode.org/">Org-Mode</a> and GDT to increase your productivity and motivation in your daily routine.
</p>
<p>
To get started with Gamify simply add this to your <code>.emacs</code>:
</p>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">gamify</span>)
(gamify-start)

</pre>
<p>
There are a few customizable variables to tweak (which you might want to check out <a href="https://github.com/Idorobots/gamify-el/blob/master/gamify.el">here</a>), but I&#8217;ll focus on the Org-Mode integration (enabled by setting <code>gamify-org-p</code> to <code>t</code>).
</p>
<p>
Whenever you complete an Org-Mode task by setting its state to <code>DONE</code> Gamify will try to interpret its tags and properties and update your stats accordingly. All you really need to do is assign some experience to your task, preferably automatically at capture-time:
</p>
<pre class="src src-emacs-lisp">(setq<span style="color:#a9a9a9;"> </span>org-capture-templates
<span style="color:#a9a9a9;">  </span>(list*<span style="color:#a9a9a9;"> </span>`(<span style="color:#ffef6b;font-style:italic;">"1"</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"New</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">easy</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">quest."</span><span style="color:#a9a9a9;"> </span>entry<span style="color:#a9a9a9;"> </span>(file<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">""</span>)
<span style="color:#a9a9a9;">               </span>,(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"*</span><span style="color:#a9a9a9;"> </span><span style="color:#ff0000;background-color:#ffff00;font-weight:bold;text-decoration:underline;">TODO</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%?\nSCHEDULED:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%t\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":PROPERTIES:\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":gamify_exp:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%(gamify-assign-some-exp</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">5</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">2)\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":END:\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">"%U\n%a\n</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%i\n"</span>))
<span style="color:#a9a9a9;">         </span>`(<span style="color:#ffef6b;font-style:italic;">"2"</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"New</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">medium</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">quest."</span><span style="color:#a9a9a9;"> </span>entry<span style="color:#a9a9a9;"> </span>(file<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">""</span>)
<span style="color:#a9a9a9;">               </span>,(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"*</span><span style="color:#a9a9a9;"> </span><span style="color:#ff0000;background-color:#ffff00;font-weight:bold;text-decoration:underline;">TODO</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%?\nSCHEDULED:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%t\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":PROPERTIES:\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":gamify_exp:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%(gamify-assign-some-exp)\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":END:\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">"%U\n%a\n</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%i\n"</span>))
<span style="color:#a9a9a9;">         </span>`(<span style="color:#ffef6b;font-style:italic;">"3"</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"New</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">hard</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">quest."</span><span style="color:#a9a9a9;"> </span>entry<span style="color:#a9a9a9;"> </span>(file<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">""</span>)
<span style="color:#a9a9a9;">               </span>,(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"*</span><span style="color:#a9a9a9;"> </span><span style="color:#ff0000;background-color:#ffff00;font-weight:bold;text-decoration:underline;">TODO</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%?\nSCHEDULED:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%t\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":PROPERTIES:\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":gamify_exp:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%(gamify-assign-some-exp</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">30</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">10)\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">":END:\n"</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">"%U\n%a\n</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%i\n"</span>))
<span style="color:#a9a9a9;">        </span>org-capture-templates))

</pre>
<p>
&hellip;and <b>tag them  by the stat they train or require</b>:
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2012/12/wpid-new.png?w=549" alt="http://idorobots.files.wordpress.com/2012/12/wpid-new.png?w=549" />
</p>
</div>
<p>
New tagging scheme might seem time and display space consuming at first, but thanks to <i>tag inheritance</i> and <i>stat aggregation</i> provided by Gamify it quickly becomes a second nature. In fact, my getting things done workflow stayed unchanged &#8211; I still capture, tag, refile and perform my tasks as usual.
</p>
<p>
What changed, however, is the amount and type of information I&#8217;m gathering &#8211; instead of &#8220;just a task archive&#8221; I now have more data to play with, to enhance my productivity and motivation, <a href="http://idorobots.files.wordpress.com/2012/12/wpid-st.png">to boldly go where no man has gone before</a>!
</p>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4">It&#8217;s not gamification if there&#8217;s no XP bar!</h2>
<div class="outline-text-2" id="text-4">
<p>Or well, you know, XP percentage indicator due to limited space of the <a href="http://idorobots.org/2012/10/10/emacs-mode-line/">Emacs mode-line</a>:
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2012/12/wpid-exp.png?w=549" alt="http://idorobots.files.wordpress.com/2012/12/wpid-exp.png?w=549" />
</p>
</div>
<p>
This little fellow does wonders. This type of feedback is essentially the core concept behind gamification itself &#8211; seeing your progress helps you stay motivated to progress even further.
</p>
<p>
Gamify includes a <a href="http://www.graphviz.org/">Graphviz dot</a> exporter to provide extra feedback &#8211; it builds a colorful graph of stats and their dependencies which shows how different stats depend on each other and how developed they are. The exporter supports filtering, so it is possible to focus on a specific part of the graph or filter out stats that are less important or less developed.
</p>
<p>
Following is an example subgraph of my skill-set. Skills that didn&#8217;t make it past filtering are barely visible on the graph not to obscure it:
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2012/12/wpid-codin51.png?w=549" alt="http://idorobots.files.wordpress.com/2012/12/wpid-codin51.png?w=549" />
</p>
</div>
<p>
There&#8217;s some useful information to be seen on this graph, for example programming languages I know or what my toolchain is. My Valgrind skill is marked red meaning that it went rusty because it wasn&#8217;t updated for a while. Perhaps that&#8217;s something I could focus on in the future? This type of data is invaluable when identifing your weak spots that require improving and it&#8217;s right there, awaiting interpretation.
</p>
<p>
With all these neat things on my side I&#8217;m not hesitant in starting new tasks anymore.
</p>
<div style="text-align:center;">
<p><img src="http://idorobots.files.wordpress.com/2012/12/wpid-notify2.png?w=549" alt="http://idorobots.files.wordpress.com/2012/12/wpid-notify2.png?w=549" />
</p>
</div>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1790/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1790/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1790&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/12/07/gamification/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/12/wpid-foo41.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/12/wpid-foo41.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/12/wpid-old1.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/12/wpid-old1.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/12/wpid-new.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/12/wpid-new.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/12/wpid-exp.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/12/wpid-exp.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/12/wpid-codin51.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/12/wpid-codin51.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/12/wpid-notify2.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/12/wpid-notify2.png</media:title>
		</media:content>
	</item>
		<item>
		<title>System monitor in Emacs mode-line</title>
		<link>http://idorobots.org/2012/10/10/emacs-mode-line/</link>
		<comments>http://idorobots.org/2012/10/10/emacs-mode-line/#comments</comments>
		<pubDate>Wed, 10 Oct 2012 16:00:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Emacs Lisp]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[.emacs]]></category>
		<category><![CDATA[CPU usage]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[load average]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[mode-line]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1692</guid>
		<description><![CDATA[Resistance is futile&#8230; As we all know Emacs is a great operating system and a decent editor, and as such it has been serving me really well &#8211; I find myself assimilating more and more of my tools and daily activities into the Emacs collective. Recently I realised that Conky just wouldn&#8217;t cut it anymore&#8230; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1692&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Resistance is futile&hellip;</h2>
<div class="outline-text-2" id="text-1">
<p>As we all know <b>Emacs</b> is a <a href="http://www.informatimago.com/linux/emacs-on-user-mode-linux.html">great operating system</a> and a decent editor, and as such it has been serving me really well &#8211; I find myself <a href="http://awsomeborgcubes.webs.com/borg-cube.jpg">assimilating</a> more and more of my tools and daily activities into the Emacs collective. Recently I realised that <a href="http://conky.sourceforge.net/">Conky</a> just wouldn&#8217;t cut it anymore&hellip;
</p>
<p>
First of all, I barely look at my desktop. There&#8217;s just no reason to do that other than checking some of the system stats such as memory usage or CPU load when I&#8217;m hacking arround and testing stuff.
</p>
<p>
For this particular use-case I figured the Emacs <a href="http://www.emacswiki.org/ModeLine">mode-line</a> would be perfect to display all the relevant statistics directly in Emacs in such a way that I could glance through them without interrupting my workflow &#8211; giving me real-time feedback with minimal distraction.<br />
<span id="more-1692"></span></p>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Package</h2>
<div class="outline-text-2" id="text-2">
<p>The <a href="https://github.com/Idorobots/mode-line-stats">package</a> I wrote contains a bunch of easy to use modules that provide various system stats directly in the Emacs mode-line:
</p>
<ul>
<li><b>cpu-stats.el</b> &#8211; provides an easy way to display various CPU stats derived from <code>/proc/stat</code>. Usage:
</li>
</ul>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">cpu-stats</span>)
(setq<span style="color:#a9a9a9;"> </span>cpu-usage-update-interval<span style="color:#a9a9a9;"> </span>1)
(setq<span style="color:#a9a9a9;"> </span>cpu-usage-format<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Average:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%A</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">CPU0:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%C0</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">CPU1:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%C1"</span>)
(cpu-usage-start)

</pre>
<ul>
<li><b>memory-stats.el</b> &#8211; display many different RAM and SWAP statistics in the mode-line. Usage:
</li>
</ul>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">memory-stats</span>)
(setq<span style="color:#a9a9a9;"> </span>memory-usage-update-interval<span style="color:#a9a9a9;"> </span>5)
(setq<span style="color:#a9a9a9;"> </span>memory-usage-format<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Mem:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%R</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Free:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%F</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Swap:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%S"</span>)
(memory-usage-start)

</pre>
<ul>
<li><b>network-speed.el</b> &#8211; displays network load in the mode-line. This one was written by <b>Vicente Hernando Ara</b> quite some time ago and cycles the net ever since. Usage:
</li>
</ul>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">network-speed</span>)
(setq<span style="color:#a9a9a9;"> </span>network-speed-update-interval<span style="color:#a9a9a9;"> </span>5)
(setq<span style="color:#a9a9a9;"> </span>network-speed-precision<span style="color:#a9a9a9;"> </span>1)
(setq<span style="color:#a9a9a9;"> </span>network-speed-interface-list<span style="color:#a9a9a9;"> </span>'(<span style="color:#ffef6b;font-style:italic;">"wlan0"</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"eth0"</span>))
(setq<span style="color:#a9a9a9;"> </span>network-speed-format-string<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Down:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%RB</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Up:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%TB"</span>)
(network-speed-start)

</pre>
<ul>
<li><b>misc-stats.el</b> &#8211; various system and Emacs stats such as load-averages, uptime etc. Usage:
</li>
</ul>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">require</span><span style="color:#a9a9a9;"> </span>'<span style="color:#76b23b;font-weight:bold;">misc-stats</span>)
(setq<span style="color:#a9a9a9;"> </span>misc-stats-update-interval<span style="color:#a9a9a9;"> </span>10)
(setq<span style="color:#a9a9a9;"> </span>misc-stats-format<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Emacs</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">uptime:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%E</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Load</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">average:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">%L1"</span>)
(misc-stats-start)

</pre>
<p>
Additionally, there are some system monitors already bundled with Emacs, such as <b>battery.el</b>, useful for laptop users.
</p>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Mode-line hacking</h2>
<div class="outline-text-2" id="text-3">
<p>The <a href="https://github.com/Idorobots/mode-line-stats">package</a> will look something like this out of the box:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2012/10/modeline.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2012/10/wpid-modeline12.png?w=549" alt="http://idorobots.files.wordpress.com/2012/10/wpid-modeline12.png?w=549" /><br />
<span style="font-size:xx-small;">(click me)</span><br />
</a>
</p>
</div>
<p>
&hellip;but with enough elbow grease you can make it look like this:
</p>
<div style="text-align:center;">
<p><a href="http://idorobots.files.wordpress.com/2012/10/modeline2.png"></p>
<p>
<img src="http://idorobots.files.wordpress.com/2012/10/wpid-modeline212.png?w=549" alt="http://idorobots.files.wordpress.com/2012/10/wpid-modeline212.png?w=549" /><br />
<span style="font-size:xx-small;">(click me)</span><br />
</a>
</p>
</div>
<p>
Let&#8217;s start with evaluating arbitrary code in the <code>mode-line-format</code> as it&#8217;s fairly simple.
</p>
<p>
You can use either <code>(:eval ...)</code> or <code>(:propertize ...)</code> in order to evaluate some code that returns a string or propertize it similarly to the <code>propertize</code> function:
</p>
<pre class="src src-emacs-lisp">(setq<span style="color:#a9a9a9;"> </span>mode-line-format
<span style="color:#a9a9a9;">  </span>(list<span style="color:#a9a9a9;"> </span>'(<span style="color:#729fcf;">:eval</span><span style="color:#a9a9a9;"> </span>(message<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Using</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">`</span><span style="color:#ffef6b;font-weight:bold;font-style:italic;">message</span><span style="color:#ffef6b;font-style:italic;">'</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">here</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">is</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">a</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">bad</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">idea..."</span>))
<span style="color:#a9a9a9;">        </span>'(<span style="color:#729fcf;">:propertize</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">No</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">really.</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">Stop</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">it!"</span>
<span style="color:#a9a9a9;">                      </span>face<span style="color:#a9a9a9;"> </span>font-lock-warning-face)
<span style="color:#a9a9a9;">  </span>))

</pre>
<p>
Propertizing mode-line strings gives us an opportunity to add colors to this boring part of the UI. For example in order to color the buffername according to the version control status of its associated file, we can add this to the <code>mode-line-format</code>:
</p>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">my-vc-alist</span><span style="color:#a9a9a9;"> </span>'(<span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Everything</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">is</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">ok:</span>
<span style="color:#a9a9a9;">                      </span>(up-to-date<span style="color:#a9a9a9;"> </span>some-green-face)
<span style="color:#a9a9a9;">                      </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Kinda</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">important:</span>
<span style="color:#a9a9a9;">                      </span>(edited<span style="color:#a9a9a9;"> </span>some-yellow-face)
<span style="color:#a9a9a9;">                      </span>(added<span style="color:#a9a9a9;"> </span>some-yellow-face)
<span style="color:#a9a9a9;">                      </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Most</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">important:</span>
<span style="color:#a9a9a9;">                      </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">                     </span>))

(setq<span style="color:#a9a9a9;"> </span>mode-line-format
<span style="color:#a9a9a9;">  </span>(list<span style="color:#a9a9a9;"> </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">         </span>'(<span style="color:#729fcf;">:eval</span><span style="color:#a9a9a9;"> </span>(<span style="color:#729fcf;font-weight:bold;">let</span><span style="color:#a9a9a9;"> </span>((file-name<span style="color:#a9a9a9;"> </span>(buffer-file-name)))
<span style="color:#a9a9a9;">              </span>(<span style="color:#729fcf;font-weight:bold;">if</span><span style="color:#a9a9a9;"> </span>file-name
<span style="color:#a9a9a9;">                  </span>(<span style="color:#729fcf;font-weight:bold;">let</span><span style="color:#a9a9a9;"> </span>((state-face<span style="color:#a9a9a9;"> </span>(assoc<span style="color:#a9a9a9;"> </span>(vc-state<span style="color:#a9a9a9;"> </span>file-name)
<span style="color:#a9a9a9;">                                           </span>my-vc-alist))
<span style="color:#a9a9a9;">                        </span>(revision<span style="color:#a9a9a9;"> </span>(vc-working-revision<span style="color:#a9a9a9;"> </span>file-name)))
<span style="color:#a9a9a9;">                    </span>(propertize<span style="color:#a9a9a9;"> </span>(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"%b"</span>
<span style="color:#a9a9a9;">                                        </span>(<span style="color:#729fcf;font-weight:bold;">when</span><span style="color:#a9a9a9;"> </span>revision
<span style="color:#a9a9a9;">                                          </span>(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">["</span><span style="color:#a9a9a9;"> </span>revision<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"]"</span>)))
<span style="color:#a9a9a9;">                                </span>'face<span style="color:#a9a9a9;"> </span>(cadr<span style="color:#a9a9a9;"> </span>state-face)))
<span style="color:#a9a9a9;">                  </span><span style="color:#ffef6b;font-style:italic;">"%b"</span>)))
<span style="color:#a9a9a9;">        </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">  </span>))

</pre>
<p>
<a href="http://i489.photobucket.com/albums/rr257/DamienStryker89/Kitty_a_cat_is_fine_too_baby.jpg">Custom tool tips are fine too:</a>
</p>
<pre class="src src-emacs-lisp">(setq<span style="color:#a9a9a9;"> </span>mode-line-format
<span style="color:#a9a9a9;">  </span>(list<span style="color:#a9a9a9;"> </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">        </span>'(<span style="color:#729fcf;">:propertize</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"%@"</span><span style="color:#a9a9a9;"> </span>help-echo<span style="color:#a9a9a9;"> </span>(concat<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Default</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">directory</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">is:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>
<span style="color:#a9a9a9;">                                             </span>default-directory)
<span style="color:#a9a9a9;">                           </span>mouse-face<span style="color:#a9a9a9;"> </span>mode-line-highlight)
<span style="color:#a9a9a9;">        </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">  </span>))

</pre>
<p>
And a neat little thing &#8211; mode-line images. This one is a little trickier since Emacs has a hard time displaying <code>.png</code>&#8216;s in the mode-line for some reason&hellip; I advise using <code>.xpm</code>&#8216;s instead:
</p>
<pre class="src src-emacs-lisp">(<span style="color:#729fcf;font-weight:bold;">defvar</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">some-image</span><span style="color:#a9a9a9;"> </span>(create-image<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"foo.xpm"</span><span style="color:#a9a9a9;"> </span>'xpm<span style="color:#a9a9a9;"> </span>nil
<span style="color:#a9a9a9;">                                 </span><span style="color:#729fcf;">:ascent</span><span style="color:#a9a9a9;"> </span>'center))

(setq<span style="color:#a9a9a9;"> </span>mode-line-format
<span style="color:#a9a9a9;">  </span>(list<span style="color:#a9a9a9;"> </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">        </span>'(<span style="color:#729fcf;">:eval</span><span style="color:#a9a9a9;"> </span>(propertize<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"unimportant"</span><span style="color:#a9a9a9;"> </span>'display<span style="color:#a9a9a9;"> </span>some-image))
<span style="color:#a9a9a9;">        </span><span style="color:#888a85;">;;</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">...</span>
<span style="color:#a9a9a9;">  </span>))

</pre>
<p>
Lastly, <a href="https://gist.github.com/3866870">here</a> you will find my lengthy, custom mode-line code*. Happy hacking.
</p>
<hr />
<span style="font-size:xx-small;">* It does not use all the stuff the package has to offer to elliminate some redundancies.</span></p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1692/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1692&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/10/10/emacs-mode-line/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/10/wpid-modeline12.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/10/wpid-modeline12.png</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/10/wpid-modeline212.png" medium="image">
			<media:title type="html">http://idorobots.files.wordpress.com/2012/10/wpid-modeline212.png</media:title>
		</media:content>
	</item>
		<item>
		<title>ASM development log 3: DSLs</title>
		<link>http://idorobots.org/2012/08/17/asm-dev-log-3/</link>
		<comments>http://idorobots.org/2012/08/17/asm-dev-log-3/#comments</comments>
		<pubDate>Fri, 17 Aug 2012 11:03:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[ASM]]></category>
		<category><![CDATA[ASM log]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[PEG]]></category>
		<category><![CDATA[reader]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1668</guid>
		<description><![CDATA[&#8220;Kajtek, you incredibly handsome stallion, what have you been doing these past few months?&#8221; &#8211; you might ask, concerned about the lack of ASM dev logs recently&#8230; Well, I&#8217;ve mostly been studying various PL design quirks and prototyping neat features such as vau calculus flavoured fexprs or the following piece of what I consider art. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1668&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&#8220;<i>Kajtek, you incredibly handsome stallion, what have you been doing these past few months?</i>&#8221; &#8211; <a href="http://i37.tinypic.com/ncjqk2.jpg">you might ask</a>, concerned about the lack of ASM dev logs recently&hellip;
</p>
<p>
Well, I&#8217;ve mostly been studying various <a href="http://en.wikipedia.org/wiki/Programming_language#Design_and_implementation">PL design</a> quirks and prototyping neat features such as <a href="http://lambda-the-ultimate.org/node/4093">vau calculus</a> flavoured <a href="http://en.wikipedia.org/wiki/Fexpr">fexprs</a> or the following piece of what I consider <a href="http://cache.ohinternet.com/images/thumb/2/2d/Trollface_HD.png/618px-Trollface_HD.png">art</a>.
</p>
<p>
As mentioned <a href="http://idorobots.org/2011/09/13/asm-dev-log-1/">before</a>, I was working on an extensible reader that would support user-defined reader macros for easy <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a> programming. It took me quite some time, effort and researching but eventually I came up with an awesome solution.<br />
It&#8217;s worthy to mention here, that it&#8217;s in no way a <a href="http://tinlizzie.org/ometa/">new solution</a>. I prefer to figure stuff out myself and often times it turns out that similar concept already existed a few years before mine. <a href="http://www.aerialnoise.com/wp-content/uploads/2012/07/Endless-Bummer-400x400.jpg">Bummer</a> <code>u_u</code>.<br />
<span id="more-1668"></span></p>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">PEG reader generator</h2>
<div class="outline-text-2" id="text-1">
<p>The idea is simple &#8211; modify the syntax of the <a href="http://idorobots.org/asm/">hosting language</a> using full capabilities of said language extending its functionality on the fly. As simple as it may sound it&#8217;s not simple at all.
</p>
<p>
Most common parsing techniques such as using <a href="http://en.wikipedia.org/wiki/Context-free_grammar">CFG</a> and <a href="http://en.wikipedia.org/wiki/LL_parser">LL(k)</a> or <a href="http://en.wikipedia.org/wiki/LR_parser">LR(k)</a> parsers are not particularly well-suited for this task, because they require a separate phase of lexical analysis which, while sounding innocently, complicated the design of the reader sufficiently enough for me to drop the idea for several weeks. Long story short, I started looking for something different but equally powerful, such as <a href="http://en.wikipedia.org/wiki/Hygienic_macro">hygienic macros</a> or fexprs with further improvements, and eventually stumbled upon <a href="http://en.wikipedia.org/wiki/Parsing_expression_grammar">this</a>.
</p>
<p>
<b>PEG</b> is a scannerless parsing technique designed as an alternative to CFG&#8217;s. PEG&#8217;s are expressive and <a href="http://bford.info/pub/lang/packrat-icfp02/">packrat</a> parsers generated for PEG&#8217;s work in guaranteed linear time thanks to memoization, but what&#8217;s most important &#8211; packrat parsers are dead <b>simple to generate</b>.
</p>
<p>
My second experimental (but most likely final) reader design is based on PEG parser generation &#8211; given a set of grammar rules and (optional) code transformations it generates immensely recursive (but not yet memoized) parser that can be easily extended with new rules thanks to (but not necessarily requiring) <a href="http://en.wikipedia.org/wiki/Late_binding">late binding</a>.
</p>
<p>
Here&#8217;s an example, which you can try out yourself by importing <code>experimental.parser2</code>:
</p>
<pre class="src src-scheme">(grammar ((Expression &lt; (/ String List Atom)))
         ((String     &lt;- (:<span style="color:#ffef6b;font-style:italic;">"\""</span>) <span style="color:#ffef6b;font-style:italic;">"[^\"]*"</span> (: <span style="color:#ffef6b;font-style:italic;">"\""</span>)))
         ((List       &lt; (: <span style="color:#ffef6b;font-style:italic;">"\\&#8203;("</span>) (* Expression) (: <span style="color:#ffef6b;font-style:italic;">"\\)"</span>))
                        `($(car List)
                          $(cdr List)))
         ((Atom       &lt;- (/ Number Symbol)))
         ((Number     &lt;- <span style="color:#ffef6b;font-style:italic;">"[+\\-]?[0-9]+(\\.[0-9]*)?"</span>)
                         `($(car Number)
                           ($(str-&gt;num (caadr Number)))))
         ((Symbol     &lt;- (! Number) <span style="color:#ffef6b;font-style:italic;">"[^\\&#8203;(\\)\"';\\s]+"</span>)
                         `($(car Symbol)
                           ($(str-&gt;symbol (caadr Symbol)))))
         ((Spacing    &lt;- (* (/ Comment <span style="color:#ffef6b;font-style:italic;">"[\\s]+"</span>))))
         ((Comment    &lt;- (: <span style="color:#ffef6b;font-style:italic;">";"</span> <span style="color:#ffef6b;font-style:italic;">"[^\n]*\n"</span>))))

(Expression <span style="color:#ffef6b;font-style:italic;">"(define (compose f g)</span>
<span style="color:#ffef6b;font-style:italic;">               (lambda (arg) (f (g arg))))"</span>)

</pre>
<p>
Few things to notice about this simple Lisp grammar definition:
</p>
<ul>
<li>It&#8217;s very succinct and it mostly resembles a formal grammar definition of Lisp.
</li>
<li>It uses quasiquotation and other hosting language features to modify the parse tree. Seemingly clumsy, code transformations will be further improved once pattern matching is implemented in the language.
</li>
<li>It uses regexps for convenience.
</li>
<li>It doesn&#8217;t look anything like PEG&#8217;s &#8211; dropping operator precedence simplifies the generator greatly. It&#8217;s quite ironic, since this reader facility will most likely be used to introduce operator precedence and complex syntax rules to ASM DSLs. The correspondence of ASM reader syntax to PEG syntax is represented on the following snippet:
</li>
</ul>
<pre class="example">sequence:        (A B C ...)   =&gt; A B C ...
ordered choice:  (/ A B C ...) =&gt; A / B / C / ...
optional branch: (? ...)     =&gt; (...)?
zero or more:    (* ...)     =&gt; (...)*
one or more:     (+ ...)     =&gt; (...)+
not:             (! ...)     =&gt; !(...)
and (lookahead): (&amp; ...)     =&gt; &amp;(...)

drop node:       (: ...)     -  Drops a node from the parse tree.
concat captures: (~ ...)     -  Concatenates captures.
</pre>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Grammar macros</h2>
<div class="outline-text-2" id="text-2">
<p>As stated above, the reader is extensible and defining new grammar rules is very straightforward:
</p>
<pre class="src src-scheme">(<span style="color:#729fcf;font-weight:bold;">syntax</span> (<span style="color:#729fcf;font-weight:bold;">Lambda</span> &lt; List (: <span style="color:#ffef6b;font-style:italic;">"-&gt;"</span>) Expression)
  `($(car Lambda)
    ((<span style="color:#729fcf;font-weight:bold;">lambda</span> $(caadr Lambda) $(cadadr Lambda)))))

(<span style="color:#729fcf;font-weight:bold;">syntax</span> (Expression &lt; (/ Lambda String List Atom)))

(Expression <span style="color:#ffef6b;font-style:italic;">"(map (x) -&gt; (* x x)</span>
<span style="color:#ffef6b;font-style:italic;">                  (list 1 2 3 4 5))"</span>)

</pre>
<p>
It also explicitly states the interaction of a new macro with the rest of the grammar making it safe to use and easy to debug.
</p>
<p>
Here&#8217;s another example, that extends ASM grammar to support direct manipulation of JSON objects:
</p>
<pre class="src src-scheme">(grammar ((JValue  &lt; (/ String Number JObject
                        JArray JTrue JFalse JNull)))
         ((JObject &lt; (: <span style="color:#ffef6b;font-style:italic;">"\\{"</span>) (? JPair (* (:<span style="color:#ffef6b;font-style:italic;">","</span>) JPair)) (:<span style="color:#ffef6b;font-style:italic;">"\\}"</span>))
           `($(car JObject)
             ($(cons 'scope (cadr JObject)))))
         ((JPair   &lt; String (: <span style="color:#ffef6b;font-style:italic;">":"</span>) JValue)
           `($(car JPair)
             ((var $(str-&gt;symbol (caadr JPair)) $(cadadr JPair)))))
         ((JArray  &lt; (:<span style="color:#ffef6b;font-style:italic;">"\\&#8203;["</span>) (? JValue (* (:<span style="color:#ffef6b;font-style:italic;">","</span>) JValue)) (:<span style="color:#ffef6b;font-style:italic;">"\\]"</span>))
           `($(car JArray)
             ($(vectorof (cadr JArray)))))
         ((JTrue   &lt;- (: <span style="color:#ffef6b;font-style:italic;">"true"</span>))
           `($(car JTrue)
             ('t)))
         ((JFalse  &lt;- (: <span style="color:#ffef6b;font-style:italic;">"false"</span>)))
         ((JNull   &lt;- (: <span style="color:#ffef6b;font-style:italic;">"null"</span>))))

(<span style="color:#729fcf;font-weight:bold;">syntax</span> (Expression &lt; (/ Quote JObject String List Atom)))

</pre>
<p>
And after running the experimental <code>REPL</code> by invoking <code>(repl)</code> you can use it like this:
</p>
<pre class="src src-javascript">(<span style="color:#729fcf;font-weight:bold;">var</span> <span style="color:#eeeeec;">json</span> { <span style="color:#ffef6b;font-style:italic;">"number"</span>: 1234.567,
            <span style="color:#ffef6b;font-style:italic;">"string"</span>: <span style="color:#ffef6b;font-style:italic;">"abcd"</span>,
            <span style="color:#ffef6b;font-style:italic;">"object"</span>: { <span style="color:#ffef6b;font-style:italic;">"member0"</span>: <span style="color:#ffef6b;font-style:italic;">"value"</span>,
                        <span style="color:#ffef6b;font-style:italic;">"member1"</span>: <span style="color:#ffef6b;font-style:italic;">"value"</span> },
            <span style="color:#ffef6b;font-style:italic;">"boolean"</span>: <span style="color:#76b23b;font-weight:bold;">true</span>,
            <span style="color:#ffef6b;font-style:italic;">"null"</span>: <span style="color:#76b23b;font-weight:bold;">null</span> })

(set! (json number) 9876.543)

</pre>
<p>
Neat, isn&#8217;t it?
</p>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Reader, writer&hellip; Compiler?</h2>
<div class="outline-text-2" id="text-3">
<p>There&#8217;s much space for improvement in the design and at the moment I&#8217;m trying to come up with a simple and natural way to sew ASM writer (facility responsible for printing ASM code) together with the reader. Ideally defining one grammar will be enough to generate both the reader and a complimentary writer, however custom writers will be possible facilitating language-to-language translation.<br />
For example, ASM&#8217; bytecode compiler might be implemented in terms of such a writer. Ahhh, the <a href="http://i717.photobucket.com/albums/ww176/archer_myka/1-line-of-symmetry.png">delicious symmetry</a>.
</p>
<p>
Most likely pattern matching and some form of <a href="http://erights.org/elib/capability/ode/ode-capabilities.html">sealer/unsealer</a> pattern will be used to achieve this.
</p>
<hr />
<span style="font-size:x-small;"></p>
<p>
I&#8217;ve recently started using <a href="https://github.com/punchagan/org2blog">Org2Blog</a> to manage this blog and it turned out to be such an awesome tool that I feel obliged to mention it here. So there&#8217;s that.<br />
</span>
</p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1668/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1668&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/08/17/asm-dev-log-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>
	</item>
		<item>
		<title>There is nothing cooler than a macr- Err&#8230; Mixin?</title>
		<link>http://idorobots.org/2012/07/20/macro-mixin/</link>
		<comments>http://idorobots.org/2012/07/20/macro-mixin/#comments</comments>
		<pubDate>Fri, 20 Jul 2012 19:01:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[Common Lisp]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[code generation]]></category>
		<category><![CDATA[code manipulation]]></category>
		<category><![CDATA[CTFE]]></category>
		<category><![CDATA[D programming language]]></category>
		<category><![CDATA[iteration]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[programming language comparison]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1533</guid>
		<description><![CDATA[One of the most distinctive features of Common Lisp and Lisp in general, are its code-generation and code-manipulation capabilities. Probably the best example is the LOOP macro &#8211; a Swiss Army knife of iteration that can do pretty much anything. The following snippet iterates a list of random numbers collecting some statistics of its contents [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1533&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One of the most distinctive features of <a href="http://pl.wikipedia.org/wiki/Common_Lisp">Common Lisp</a> and Lisp in general, are its <b>code-generation</b> and <b>code-manipulation</b> capabilities.
</p>
<p>
Probably the best example is the <a href="http://www.gigamonkeys.com/book/loop-for-black-belts.html"><code>LOOP</code></a> macro &#8211; a Swiss Army knife of iteration that can do pretty much <a href="http://en.wikipedia.org/wiki/Turing_completeness">anything</a>. The following snippet iterates a list of random numbers collecting some statistics of its contents and does that while being very concise and readable:
</p>
<pre class="src src-common-lisp">(<span style="color:#729fcf;font-weight:bold;">let</span><span style="color:#a9a9a9;"> </span>((random<span style="color:#a9a9a9;"> </span>(<span style="color:#729fcf;font-weight:bold;">loop</span><span style="color:#a9a9a9;"> </span>with<span style="color:#a9a9a9;"> </span>max<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>500
<span style="color:#a9a9a9;">                    </span>for<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>from<span style="color:#a9a9a9;"> </span>0<span style="color:#a9a9a9;"> </span>to<span style="color:#a9a9a9;"> </span>max
<span style="color:#a9a9a9;">                    </span>collect<span style="color:#a9a9a9;"> </span>(random<span style="color:#a9a9a9;"> </span>max))))
<span style="color:#a9a9a9;">  </span>(<span style="color:#729fcf;font-weight:bold;">loop</span><span style="color:#a9a9a9;"> </span>for<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>in<span style="color:#a9a9a9;"> </span>random
<span style="color:#a9a9a9;">          </span>counting<span style="color:#a9a9a9;"> </span>(evenp<span style="color:#a9a9a9;"> </span>i)<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>evens
<span style="color:#a9a9a9;">          </span>counting<span style="color:#a9a9a9;"> </span>(oddp<span style="color:#a9a9a9;"> </span>i)<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>odds
<span style="color:#a9a9a9;">          </span>summing<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>total
<span style="color:#a9a9a9;">          </span>maximizing<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>max
<span style="color:#a9a9a9;">          </span>minimizing<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>min
<span style="color:#a9a9a9;">        </span>finally<span style="color:#a9a9a9;"> </span>(format<span style="color:#a9a9a9;"> </span>t<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"Stats:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">~A"</span>
<span style="color:#a9a9a9;">                          </span>(list<span style="color:#a9a9a9;"> </span>min<span style="color:#a9a9a9;"> </span>max<span style="color:#a9a9a9;"> </span>total<span style="color:#a9a9a9;"> </span>evens<span style="color:#a9a9a9;"> </span>odds))))
</pre>
<pre class="example">Stats: (0 499 120808 261 240)
</pre>
<p><span id="more-1533"></span></p>
<p>
<a href="https://github.com/Idorobots/cl-goodies">Here</a>&#8216;s my version written in the <a href="http://dlang.org">D programming language</a>.<br />
It uses <a href="http://en.wikipedia.org/wiki/Compile_time_function_execution">CTFE</a> to transform LOOP definitions and <b>generate D code at compile time</b> while mixing it together with the rest of the code extending the language with a <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a> of similar capabilities:
</p>
<pre class="src src-d"><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">random</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">mixin</span>(Loope!q{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">with</span><span style="color:#a9a9a9;"> </span>max<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>500
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span><span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>from<span style="color:#a9a9a9;"> </span>0<span style="color:#a9a9a9;"> </span>to<span style="color:#a9a9a9;"> </span>max
<span style="color:#a9a9a9;">      </span>collect<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>uniform(0,<span style="color:#a9a9a9;"> </span>max)<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
});

<span style="color:#729fcf;font-weight:bold;">mixin</span>(Loop!q{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span><span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">in</span><span style="color:#a9a9a9;"> </span>random
<span style="color:#a9a9a9;">      </span>counting<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>(i&amp;1)<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>evens
<span style="color:#a9a9a9;">      </span>counting<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>(i&amp;1)<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>1<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>odds
<span style="color:#a9a9a9;">      </span>summing<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>total
<span style="color:#a9a9a9;">      </span>maximizing<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>max
<span style="color:#a9a9a9;">      </span>minimizing<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>min
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">finally</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>writeln(<span style="color:#ffef6b;font-style:italic;">"Stats:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>,<span style="color:#a9a9a9;"> </span>[min,<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">max</span>,<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">total</span>,<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">evens</span>,<span style="color:#a9a9a9;"> </span>odds])<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
});
</pre>
<pre class="example">Stats: [2, 499, 126399, 229, 271]
</pre>
<p>
To compile this, D&#8217;s compiler first parses <code>LOOP</code> definitions passed to the <code>Loop</code> template using a parser generated (optionally at compile-time ;)) by Philippe Sigaud&#8217;s <a href="https://github.com/PhilippeSigaud/Pegged">Pegged</a> parser generator.<br />
After that it traverses the parse tree translating it into valid D code, resulting in this, full of type-inference and meaningless identifiers, <b>monstrosity</b>:
</p>
<pre class="src src-d"><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">random</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>(()<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">max</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>500;
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">__i_0</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>max;
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">i</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>0;
<span style="color:#a9a9a9;">    </span>typeof(uniform(0,<span style="color:#a9a9a9;"> </span>max))[]<span style="color:#a9a9a9;"> </span>__accumulator;

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span>(;;)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">if</span>(i<span style="color:#a9a9a9;"> </span>&gt;=<span style="color:#a9a9a9;"> </span>__i_0)<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">break</span>;

<span style="color:#a9a9a9;">        </span>__accumulator<span style="color:#a9a9a9;"> </span>~=<span style="color:#a9a9a9;"> </span>uniform(0,<span style="color:#a9a9a9;"> </span>max);

<span style="color:#a9a9a9;">        </span>i<span style="color:#a9a9a9;"> </span>+=<span style="color:#a9a9a9;"> </span>1;
<span style="color:#a9a9a9;">    </span>}
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">return</span><span style="color:#a9a9a9;"> </span>__accumulator;
})();

{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">__i_0</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>0;
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">__i_1</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>random;
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">__i_2</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>__i_1.length;
<span style="color:#a9a9a9;">    </span>typeof(__i_1.init[&#8203;0])<span style="color:#a9a9a9;"> </span>i;
<span style="color:#a9a9a9;">    </span><span style="color:#76b23b;font-weight:bold;">uint</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">evens</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>0;
<span style="color:#a9a9a9;">    </span><span style="color:#76b23b;font-weight:bold;">uint</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">odds</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>0;
<span style="color:#a9a9a9;">    </span>typeof(i)<span style="color:#a9a9a9;"> </span>total;
<span style="color:#a9a9a9;">    </span><span style="color:#76b23b;font-weight:bold;">bool</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">__max_3</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">false</span>;
<span style="color:#a9a9a9;">    </span>typeof(i)<span style="color:#a9a9a9;"> </span>max;
<span style="color:#a9a9a9;">    </span><span style="color:#76b23b;font-weight:bold;">bool</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">__min_4</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">false</span>;
<span style="color:#a9a9a9;">    </span>typeof(i)<span style="color:#a9a9a9;"> </span>min;

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span>(;;)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">if</span>(__i_0<span style="color:#a9a9a9;"> </span>&gt;=<span style="color:#a9a9a9;"> </span>__i_2)<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">break</span>;
<span style="color:#a9a9a9;">        </span>i<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>__i_1[__i_0];

<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">if</span>((i&amp;1)<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0)<span style="color:#a9a9a9;"> </span>++evens;
<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">if</span>((i&amp;1)<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>1)<span style="color:#a9a9a9;"> </span>++odds;
<span style="color:#a9a9a9;">        </span>total<span style="color:#a9a9a9;"> </span>+=<span style="color:#a9a9a9;"> </span>i;
<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">if</span>(!__max_3<span style="color:#a9a9a9;"> </span>||<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>&gt;<span style="color:#a9a9a9;"> </span>max)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">            </span>max<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>i;
<span style="color:#a9a9a9;">            </span>__max_3<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">true</span>;
<span style="color:#a9a9a9;">        </span>}
<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">if</span>(!__min_4<span style="color:#a9a9a9;"> </span>||<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>&lt;<span style="color:#a9a9a9;"> </span>min)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">            </span>min<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>i;
<span style="color:#a9a9a9;">            </span>__min_4<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">true</span>;
<span style="color:#a9a9a9;">        </span>}

<span style="color:#a9a9a9;">        </span>++__i_0;
<span style="color:#a9a9a9;">    </span>}
<span style="color:#a9a9a9;">    </span>writeln(<span style="color:#ffef6b;font-style:italic;">"Stats:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>,<span style="color:#a9a9a9;"> </span>[min,<span style="color:#a9a9a9;"> </span>max,<span style="color:#a9a9a9;"> </span>total,<span style="color:#a9a9a9;"> </span>evens,<span style="color:#a9a9a9;"> </span>odds]);
}
</pre>
<p>
That&#8217;s <b>more than three times the volume</b> of the previous snippet and it&#8217;s not nearly as readable. Imagine writing it yourself each time. The real fun, however, starts with complex loops:
</p>
<pre class="src src-d"><span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">random</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>randomStuff();<span style="color:#a9a9a9;">  </span><span style="color:#888a85;">//</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Implemented</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">elswhere.</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">;)</span>

<span style="color:#729fcf;font-weight:bold;">auto</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">result</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">mixin</span>(Loope!q{
<span style="color:#a9a9a9;">    </span>initially<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>writeln(<span style="color:#ffef6b;font-style:italic;">"Loop</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">test:"</span>);<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">with</span><span style="color:#a9a9a9;"> </span>isEven<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>(<span style="color:#76b23b;font-weight:bold;">uint</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">x</span>)<span style="color:#a9a9a9;"> </span>=&gt;<span style="color:#a9a9a9;"> </span>((x&amp;1)<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0)<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">with</span><span style="color:#a9a9a9;"> </span>updateAnalysis<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span><span style="color:#888a85;">//</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">A</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">D</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">function</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">analysing</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">our</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">data.</span>
<span style="color:#a9a9a9;">                             </span>(<span style="color:#76b23b;font-weight:bold;">uint</span>[]<span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">stats</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">                               </span><span style="color:#729fcf;font-weight:bold;">static</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">count</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>0;
<span style="color:#a9a9a9;">                               </span><span style="color:#729fcf;font-weight:bold;">if</span>(count++<span style="color:#a9a9a9;"> </span>%<span style="color:#a9a9a9;"> </span>10<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0)
<span style="color:#a9a9a9;">                                   </span>writeln(<span style="color:#ffef6b;font-style:italic;">"Analysis:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>,<span style="color:#a9a9a9;"> </span>stats);
<span style="color:#a9a9a9;">                             </span>}<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">with</span><span style="color:#a9a9a9;"> </span>max<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>500
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">with</span><span style="color:#a9a9a9;"> </span>data<span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span><span style="color:#888a85;">//</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">Yo</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">dawg...</span>
<span style="color:#a9a9a9;">                  </span><span style="color:#729fcf;font-weight:bold;">mixin</span>(Loope!q{
<span style="color:#a9a9a9;">                      </span><span style="color:#729fcf;font-weight:bold;">for</span><span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>from<span style="color:#a9a9a9;"> </span>0.0<span style="color:#a9a9a9;"> </span>to<span style="color:#a9a9a9;"> </span>max<span style="color:#a9a9a9;"> </span>by<span style="color:#a9a9a9;"> </span>1.337
<span style="color:#a9a9a9;">                        </span>collect<span style="color:#a9a9a9;"> </span>i
<span style="color:#a9a9a9;">                  </span>});<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span><span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>from<span style="color:#a9a9a9;"> </span>0<span style="color:#a9a9a9;"> </span>to<span style="color:#a9a9a9;"> </span>max
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span><span style="color:#a9a9a9;"> </span>datum<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">in</span><span style="color:#a9a9a9;"> </span>data
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">for</span><span style="color:#a9a9a9;"> </span>r<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">in</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>sort(random)<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;

<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">if</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>isEven(i)<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
<span style="color:#a9a9a9;">        </span>minimize<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>minEven<span style="color:#a9a9a9;"> </span>and
<span style="color:#a9a9a9;">        </span>maximize<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>maxEven<span style="color:#a9a9a9;"> </span>and
<span style="color:#a9a9a9;">        </span>unless<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>%<span style="color:#a9a9a9;"> </span>4<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
<span style="color:#a9a9a9;">          </span>sum<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>evenNotFoursTotal<span style="color:#a9a9a9;"> </span>and
<span style="color:#a9a9a9;">          </span>collect<span style="color:#a9a9a9;"> </span>datum<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>floats
<span style="color:#a9a9a9;">        </span>end
<span style="color:#a9a9a9;">        </span>and<span style="color:#a9a9a9;"> </span>sum<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>evenTotal
<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">else</span>
<span style="color:#a9a9a9;">        </span>minimize<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>minOdd<span style="color:#a9a9a9;"> </span>and
<span style="color:#a9a9a9;">        </span>maximize<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>maxOdd<span style="color:#a9a9a9;"> </span>and
<span style="color:#a9a9a9;">        </span>when<span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>%<span style="color:#a9a9a9;"> </span>5<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
<span style="color:#a9a9a9;">          </span>sum<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>fivesTotal<span style="color:#a9a9a9;"> </span>and
<span style="color:#a9a9a9;">          </span>collect<span style="color:#a9a9a9;"> </span>r<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>randoms
<span style="color:#a9a9a9;">        </span>end
<span style="color:#a9a9a9;">        </span>and<span style="color:#a9a9a9;"> </span>sum<span style="color:#a9a9a9;"> </span>i<span style="color:#a9a9a9;"> </span>into<span style="color:#a9a9a9;"> </span>oddTotal

<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">do</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>updateAnalysis([minEven,<span style="color:#a9a9a9;"> </span>maxEven,<span style="color:#a9a9a9;"> </span>minOdd,
<span style="color:#a9a9a9;">                            </span>maxOdd,<span style="color:#a9a9a9;"> </span>evenTotal,<span style="color:#a9a9a9;"> </span>oddTotal,
<span style="color:#a9a9a9;">                            </span>evenNotFoursTotal])<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;

<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">finally</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>writeln(<span style="color:#ffef6b;font-style:italic;">"Floats:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>,<span style="color:#a9a9a9;"> </span>floats);<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">finally</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span>writeln(<span style="color:#ffef6b;font-style:italic;">"Randoms:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>,<span style="color:#a9a9a9;"> </span>randoms);<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;

<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">finally</span><span style="color:#a9a9a9;"> </span>$&#8203;$<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">return</span><span style="color:#a9a9a9;"> </span>[minEven,<span style="color:#a9a9a9;"> </span>maxEven,<span style="color:#a9a9a9;"> </span>minOdd,
<span style="color:#a9a9a9;">                         </span>maxOdd,<span style="color:#a9a9a9;"> </span>evenTotal,<span style="color:#a9a9a9;"> </span>oddTotal,
<span style="color:#a9a9a9;">                         </span>evenNotFoursTotal];<span style="color:#a9a9a9;"> </span>$&#8203;$&#8203;
});
writeln(<span style="color:#ffef6b;font-style:italic;">"Result:</span><span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"</span>,<span style="color:#a9a9a9;"> </span>result);
</pre>
<p>
Just as the Lisp&#8217; LOOP macro (not as elegantly, though) it blends together really well with the host language allowing for arbitrary D code to be used inside of the loop (<a href="http://i188.photobucket.com/albums/z275/bulla564/xzibit_meme_7219_RE_Wtf_am_i_reading-s510x334-157605-580.jpg">including <code>Loop</code> template itself</a>).
</p>
<p>
The code generator, however, is very different to any Common Lisp <code>LOOP</code> implementation. D being a <b>statically typed language</b> with complex, unlike Lisp, syntax lacks symbol manipulation and <a href="http://en.wikipedia.org/wiki/Backtick#Use_in_programming">quasiquote</a>, meaning it has to rely on string processing, CTFE and string mixins that, despite being highly experimental and prone to performance issues, are still very powerful.
</p>
<p>
Also&hellip; There is a <a href="http://dlang.org/lex.html"><code>macro</code> keyword</a> reserved for future use in the language.
</p>
<p>
Fingers crossed for this one. ;)
</p>
<hr />
<span style="font-size:x-small;"> The title refers to <a href="http://www.youtube.com/watch?v=HM1Zb3xmvMc">this</a> video. </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1533/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1533&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/07/20/macro-mixin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>
	</item>
		<item>
		<title>What motivates me?</title>
		<link>http://idorobots.org/2012/06/08/what-motivates-me/</link>
		<comments>http://idorobots.org/2012/06/08/what-motivates-me/#comments</comments>
		<pubDate>Fri, 08 Jun 2012 10:15:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[motivation]]></category>
		<category><![CDATA[online courses]]></category>
		<category><![CDATA[Udacity]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1484</guid>
		<description><![CDATA[A quick post, despite being all busy and stuff, that answers a few questions for the Greater Good. What motivates you to complete a Udacity course? Most importantly the knowledge that is easily accessible. It&#8217;s really attractive for me to take a course on a topic of my interest especially when it saves me the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1484&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>A quick post, despite being <a href="http://weknowmemes.com/wp-content/uploads/2012/05/studying-for-finals.jpg">all busy and stuff</a>, that answers <a href="http://udacity.blogspot.com/2012/06/what-is-your-motivation.html">a few questions</a> for the Greater Good.<br />
<span id="more-1484"></span></p>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">What motivates you to complete a Udacity course?</h2>
<div class="outline-text-2" id="text-1">
<p>Most importantly the knowledge that is easily accessible.<br />
It&#8217;s really attractive for me to take a course on a topic of my interest especially when it saves me the time I would otherwise spend on digging through the web researching stuff.<br />
Secondly, initiatives such as Udacity (and the like) attract communities of people with whom I can share my thoughts and resolve any encountered problems. That&#8217;s the only kind of social interaction I, being <a href="http://awgeezmargie.files.wordpress.com/2010/06/nerd-1.jpg">an introverted CS student</a>, accept. ;)
</p>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">How useful are deadlines?</h2>
<div class="outline-text-2" id="text-2">
<p>Very useful.<br />
I&#8217;m the weird kind of person that <b>needs</b> his deadlines listed somewhere in order to get stuff done. It keeps me motivated and sets a certain priority for a task, the higher the closer its deadline is. When there&#8217;s no deadline it&#8217;ll just sink among all the other daily activities and eventually end up as &#8220;CANCELLED&#8221; in my Org-Mode archive. Now, scheduling deadlines on my own and keeping them is a lot harder than keeping a fixed, preset deadline. For some reason my own deadlines don&#8217;t seem important enough.
</p>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">If you have not completed a course, what kept you from finishing it?</h2>
<div class="outline-text-2" id="text-3">
<p>Currently I&#8217;m taking the <a href="https://www.coursera.org/course/compilers">Compilers course</a> from Coursera <span style="font-size:xx-small;">(hope you guys don&#8217;t mind me mentioning your competitors ;))</span> but I had to cease doing the homework assignments solely because they took too much time to complete.</p>
<p>
Compilers course lacks the neat balance that Udacity managed to maintain so far (judging on CS373 and AI-Class); the homework assignments aren&#8217;t hard but they consume a lot of time. Contrary, CS373 homework asignments were neither too hard nor too simple, meaning they were fun to complete, and most importantly they took adequate amounts of time.
</p>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4">What do you think Udacity could do to motivate you to complete a course?</h2>
<div class="outline-text-2" id="text-4">
<p>Two things for sure &#8211; keep the courses as entertaining, interesting and well-prepared and keep the neat balance I&#8217;ve mentioned earlier. I have yet to try a programming competition (such as the one held for CS101 students) but I suppose a little competition always is a nice touch.
</p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1484/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1484&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/06/08/what-motivates-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>
	</item>
		<item>
		<title>I do robots Beamer theme</title>
		<link>http://idorobots.org/2012/05/05/i-do-theme/</link>
		<comments>http://idorobots.org/2012/05/05/i-do-theme/#comments</comments>
		<pubDate>Sat, 05 May 2012 00:04:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[hacks]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[beamer]]></category>
		<category><![CDATA[frame numbering]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[sleek]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1454</guid>
		<description><![CDATA[Recently I&#8217;ve been looking for a simple and readable Beamer theme but all of the ones I found lacked something in one way or another. Finally, I settled for a theme of my own &#8211; based on Amsterdam theme by Rogier Koppejan adding frame numbering to the footer. It&#8217;s simple, it&#8217;s sleek. It&#8217;s all I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1454&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;ve been looking for a simple and readable <b>Beamer</b> theme but all of the ones I found lacked something in one way or another. Finally, I settled for a theme of my own &#8211; based on <b>Amsterdam</b> theme by Rogier Koppejan adding frame numbering to the footer. It&#8217;s simple, it&#8217;s sleek. It&#8217;s all I want.
</p>
<p><a href="http://student.agh.edu.pl/~krzepeck/stuff/beamerthemeIdorobots.sty"><img src="http://idorobots.files.wordpress.com/2012/05/idotheme.png?w=549" alt="" title="idotheme"   class="aligncenter size-full wp-image-1456" /></a></p>
<p>
<a href="http://idorobots.files.wordpress.com/2012/05/idorobots.pdf">Here</a> you can find a few sample slides using the theme and <a href="http://student.agh.edu.pl/~krzepeck/stuff/beamerthemeIdorobots.sty">here</a> you&#8217;ll find the theme itself.
</p>
<p>
It consists of a header containing outline of the presentation and a footer containing navigation box and all the necessary info such as authors name and institute, presentation title and a frame counter.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1454/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1454&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/05/05/i-do-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://idorobots.files.wordpress.com/2012/05/idotheme.png" medium="image">
			<media:title type="html">idotheme</media:title>
		</media:content>
	</item>
		<item>
		<title>Templated Monads? Monadic Templates?</title>
		<link>http://idorobots.org/2012/04/15/monads-in-d/</link>
		<comments>http://idorobots.org/2012/04/15/monads-in-d/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 16:57:00 +0000</pubDate>
		<dc:creator>Kajtek</dc:creator>
				<category><![CDATA[D]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[Binary Tree]]></category>
		<category><![CDATA[D programming language]]></category>
		<category><![CDATA[D templates]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://idorobots.org/?p=1420</guid>
		<description><![CDATA[So, I finally found some time for a Template Metaranting follow-up post. This time let&#8217;s get down to business as this one contains a fair amount of code. Sadly, I won&#8217;t rant as much but instead I&#8217;ll try to show how awesome D&#8216;s templates really are. We&#8217;ll write a piece of code, based on this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1420&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>So, I finally found some time for a <a href="http://idorobots.org/2012/03/07/template-metaranting/">Template Metaranting</a> follow-up post. This time let&#8217;s get down to business as this one contains a fair amount of code.
</p>
<p>
Sadly, I won&#8217;t rant as much but instead I&#8217;ll try to show how <b>awesome</b> <a href="http://dlang.org/index.html">D</a>&#8216;s templates really are. We&#8217;ll write a piece of code, based on <a href="http://okmij.org/ftp/Scheme/monad-in-Scheme.html">this Scheme implementation</a>, that is, a simple <a href="http://en.wikipedia.org/wiki/Monad_(functional_programming)">monad</a> that we&#8217;ll use to build a binary tree, with uniquely numbered nodes containing their height, without any global state (therefore <a href="http://en.wikipedia.org/wiki/Functional_programming">purely</a>) <b>entirely at compile time</b>.
</p>
<p style="text-align:center;"><a href="http://i3.kym-cdn.com/entries/icons/original/000/003/891/grab_my_boobs.jpg">Quick Reader, grab my code!<br />
ADVENTURE!</a></p>
<p><span id="more-1420"></span></p>
<p>
Let&#8217;s jump straight in, shall we?
</p>
<pre class="src src-d"><span style="color:#729fcf;font-weight:bold;">import</span><span style="color:#a9a9a9;"> </span>std.<span style="color:#76b23b;font-weight:bold;">typecons</span>;

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">MakeNumberedValue</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">tag</span>,<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">val</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">MakeNumberedValue</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>tuple(tag,<span style="color:#a9a9a9;"> </span>val);
}

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">NumberedValue</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">tv</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">NumberedValue</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>tv[<span style="color:#a9a9a9;"> </span>1];
}

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">NumberedTag</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">tv</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">NumberedTag</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>tv[<span style="color:#a9a9a9;"> </span>0];
}

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Return</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">value</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Return</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">counter</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">MakeNumberedValue</span>!(counter,<span style="color:#a9a9a9;"> </span>value)<span style="color:#a9a9a9;"> </span>Return;
<span style="color:#a9a9a9;">  </span>}
}

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Bind</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">M</span>,<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">F</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Bind</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">counter</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">t</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>NumberedTag!(M!counter);
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">v</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>NumberedValue!(M!counter);
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">F</span>!v<span style="color:#a9a9a9;"> </span>M1;

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">M1</span>!t<span style="color:#a9a9a9;"> </span>Bind;
<span style="color:#a9a9a9;">  </span>}
}

</pre>
<p>
So&hellip; That&#8217;s all. That&#8217;s the monad.<br />
We define several simple templates that manage our numbered pairs. A pair consists of a unique tag and a value it stores.<br />
Next we define two basic monad operations &#8211; that is &#8211; <b>bind</b> (<code>&gt;&gt;=</code>) and <b>return</b> (well&hellip; <code>return</code>).<br />
I&#8217;ll leave checking the <a href="http://www.haskell.org/haskellwiki/Monad_laws">Monad Laws</a> to the Reader as I&#8217;m too lazy to do it myself <img src="http://i41.tinypic.com/10rr31g.png" alt="http://i41.tinypic.com/10rr31g.png" />.
</p>
<p>
Let&#8217;s now build the binary tree analogically to the original Scheme implementation:
</p>
<pre class="src src-d"><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">Increment</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">n</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Increment</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>MakeNumberedValue!(n+1,<span style="color:#a9a9a9;"> </span>n);
}

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">MakeNode</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">value</span>,<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">kids</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">__Lambda</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">counter</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Return</span>!(<span style="color:#76b23b;font-weight:bold;">tuple</span>(MakeNumberedValue!(counter,<span style="color:#a9a9a9;"> </span>value),<span style="color:#a9a9a9;"> </span>kids))
<span style="color:#a9a9a9;">          </span>__Lambda;
<span style="color:#a9a9a9;">  </span>}

<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Bind</span>!(Increment,<span style="color:#a9a9a9;"> </span>__Lambda)<span style="color:#a9a9a9;"> </span>MakeNode;
}

<span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">BuildBtree</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">depth</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">static</span><span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">if</span>(depth<span style="color:#a9a9a9;"> </span>==<span style="color:#a9a9a9;"> </span>0)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">MakeNode</span>!(depth,<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>)<span style="color:#a9a9a9;"> </span>BuildBtree;<span style="color:#a9a9a9;"> </span><span style="color:#888a85;">//</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">The</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">leaf</span><span style="color:#a9a9a9;"> </span><span style="color:#888a85;">node.</span>
<span style="color:#a9a9a9;">  </span>}
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">else</span><span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#eeeeec;">__Lambda1</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">left</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">__Lambda2</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">right</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">        </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">MakeNode</span>!(depth,<span style="color:#a9a9a9;"> </span>tuple(left,<span style="color:#a9a9a9;"> </span>right))<span style="color:#a9a9a9;"> </span>__Lambda2;
<span style="color:#a9a9a9;">      </span>}

<span style="color:#a9a9a9;">      </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Bind</span>!(BuildBtree!(depth-1),<span style="color:#a9a9a9;"> </span>__Lambda2)<span style="color:#a9a9a9;"> </span>__Lambda1;
<span style="color:#a9a9a9;">    </span>}

<span style="color:#a9a9a9;">    </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">Bind</span>!(BuildBtree!(depth-1),<span style="color:#a9a9a9;"> </span>__Lambda1)<span style="color:#a9a9a9;"> </span>BuildBtree;
<span style="color:#a9a9a9;">  </span>}
}

</pre>
<p>
This part is a little less readable as there are no anonymous templates in D (what would that even be?).<br />
I won&#8217;t bother explaining this snippet as it&#8217;s pretty involved, it contains <b>nested templates</b>, <b>template aliases</b>, <b>static conditionals</b> and a standard library defined <a href="http://en.wikipedia.org/wiki/Tuple">tuple</a> &#8211; several of D&#8217;s numerous template goodies.
</p>
<p>
Just <b>enjoy</b> it. &lt;3
</p>
<p>
Lastly, we need to &#8220;run&#8221; the monad and output it to the console:
</p>
<pre class="src src-d"><span style="color:#729fcf;font-weight:bold;">template</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">RunMonad</span>(<span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">M</span>,<span style="color:#a9a9a9;"> </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">counter</span>)<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">alias</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">M</span>!counter<span style="color:#a9a9a9;"> </span>RunMonad;
}

<span style="color:#76b23b;font-weight:bold;">void</span><span style="color:#a9a9a9;"> </span><span style="color:#edd400;font-weight:bold;font-style:italic;">main</span>()<span style="color:#a9a9a9;"> </span>{
<span style="color:#a9a9a9;">  </span><span style="color:#729fcf;font-weight:bold;">enum</span><span style="color:#a9a9a9;"> </span><span style="color:#76b23b;font-weight:bold;">numberedBinaryTree</span><span style="color:#a9a9a9;"> </span>=<span style="color:#a9a9a9;"> </span>RunMonad!(BuildBtree!3,<span style="color:#a9a9a9;"> </span>100);
<span style="color:#a9a9a9;">  </span>pragma(msg,<span style="color:#a9a9a9;"> </span>numberedBinaryTree);
}

</pre>
<p>
This code creates a <code>numberedBinaryTree</code> of depth 3, each node with a unique identifier starting with 100.<br />
I used <a href="http://dlang.org/pragma.html"><code>pragma(msg, &hellip;)</code></a> to output the tree just to make it clear that it was, indeed, created at compile time.<br />
Here&#8217;s the &#8220;pretty-formatted&#8221; output that shows our binary tree:
</p>
<pre class="src src-d">Tuple(115,<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">  </span>Tuple(114,<span style="color:#a9a9a9;"> </span>3),Tuple(Tuple(
<span style="color:#a9a9a9;">    </span>Tuple(106,<span style="color:#a9a9a9;"> </span>2),<span style="color:#a9a9a9;"> </span>Tuple(Tuple(
<span style="color:#a9a9a9;">      </span>Tuple(102,<span style="color:#a9a9a9;"> </span>1),<span style="color:#a9a9a9;"> </span>Tuple(Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(100,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(101,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>))),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">      </span>Tuple(105,<span style="color:#a9a9a9;"> </span>1),<span style="color:#a9a9a9;"> </span>Tuple(Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(103,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(104,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>))))),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">    </span>Tuple(113,<span style="color:#a9a9a9;"> </span>2),<span style="color:#a9a9a9;"> </span>Tuple(Tuple(
<span style="color:#a9a9a9;">      </span>Tuple(109,<span style="color:#a9a9a9;"> </span>1),<span style="color:#a9a9a9;"> </span>Tuple(Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(107,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(108,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>))),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">      </span>Tuple(112,<span style="color:#a9a9a9;"> </span>1),<span style="color:#a9a9a9;"> </span>Tuple(Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(110,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>),<span style="color:#a9a9a9;"> </span>Tuple(
<span style="color:#a9a9a9;">        </span>Tuple(111,<span style="color:#a9a9a9;"> </span>0),<span style="color:#a9a9a9;"> </span><span style="color:#ffef6b;font-style:italic;">"leaf"</span>))))))))

</pre>
<p>
It may not be as readable as the Scheme version, but that&#8217;s a small price to pay.<br />
Now don&#8217;t get me wrong, this fairly involved code just shows the capabilities of D&#8217;s templates &#8211; you can implement such complex ideas as monads very easily. Additionally, it maps nearly directly to the Scheme code.<br />
That&#8217;s a yet another reason I like D so much.
</p>
<p><span style="font-size:x-small;">BTW, I might write a little more useful monad as a followup to this post, to show that this can be, in fact, useful. <strong>Stay tuned.</strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/idorobots.wordpress.com/1420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/idorobots.wordpress.com/1420/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=idorobots.org&#038;blog=21396138&#038;post=1420&#038;subd=idorobots&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://idorobots.org/2012/04/15/monads-in-d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a2ae8db0ed08728dffebe07c48fa48db?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">idorobots</media:title>
		</media:content>

		<media:content url="http://i41.tinypic.com/10rr31g.png" medium="image">
			<media:title type="html">http://i41.tinypic.com/10rr31g.png</media:title>
		</media:content>
	</item>
	</channel>
</rss>
