<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adztec Independent - Blog &#187; functional</title>
	<atom:link href="http://www.adztec-independent.de/tag/functional/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adztec-independent.de</link>
	<description>Programming Ruby / JRuby / Rails / Common Lisp by Christopher Bertels</description>
	<lastBuildDate>Mon, 13 Sep 2010 22:58:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>New Project: The Fancy Programming Language</title>
		<link>http://www.adztec-independent.de/2010/03/new-project-the-fancy-programming-language/</link>
		<comments>http://www.adztec-independent.de/2010/03/new-project-the-fancy-programming-language/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 21:37:22 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[fancy]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[hobbies]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[meta-programming]]></category>
		<category><![CDATA[parallel programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=278</guid>
		<description><![CDATA[Ok, I know I&#8217;m not a frequent poster. I guess, that&#8217;s just the way it is. Anyways..
I&#8217;ve been up to a lot of stuff in the past few months. Related to programming there are two projects, one of them I&#8217;m still working on (and intend to do so for the forseeable future):

generica, a small, simple [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, I know I&#8217;m not a frequent poster. I guess, that&#8217;s just the way it is. Anyways..</p>
<p>I&#8217;ve been up to a lot of stuff in the past few months. Related to programming there are two projects, one of them I&#8217;m still working on (and intend to do so for the forseeable future):</p>
<ul>
<li><a href="http://github.com/bakkdoor/generica">generica</a>, a small, simple &amp; dirty lisp-like language interpreter implemented in ANSI C.</li>
<li>and <a href="http://github.com/bakkdoor/fancy/">Fancy</a>, a new object-oriented dynamic programming language, heavily inspired by Ruby, Smalltalk and Erlang. There&#8217;s also a website up, but far from finished: <a href="http://fancy-lang.org">fancy-lang.org</a> &#8211; Check it out if you like <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>So yeah, the latter project I started about 6 weeks ago but didn&#8217;t have the time to really work on it until about 3 weeks ago. Since then I&#8217;ve managed to implement quite a few features.<br />
Here&#8217;s a small overview of features working in Fancy already:</p>
<ul>
<li>Class definitions</li>
<li>Method definitions</li>
<li>String, Integer, Double, Array, Hash (Hashmap), and Block (lambda function / closure) Literals</li>
<li>Method and operator calls (<em>sending messages to objects</em>)</li>
<li>Simple loops</li>
<li>Support for closures (performance improvements are definately possible though <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )</li>
</ul>
<p>There&#8217;s still lots of stuff missing, obviously. Mainly most of the standard library (I/O, Threading/Concurrency, Networking, etc&#8230;) will have to implemented as well as some runtime features I haven&#8217;t finished or started yet. But it&#8217;s getting along quite nicely. If anyone dares to try it out, I&#8217;d love to hear some feedback, especially hearing some opinions on the overall feel and semantics of the language would be nice. You can get the code on github (see the link above) and try to build it. Compiling instructions are in the README file. Fancy is licensed under the GNU LGPL.</p>
<p>I&#8217;m still excited to see where this is gonna go, for myself and possibly others as well. We&#8217;ll see.</p>
<p>I&#8217;ll probably post some more information on the language and its implementation some time soon. Need to go now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2010/03/new-project-the-fancy-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blockd: Mixing Ruby &amp; Smalltalk</title>
		<link>http://www.adztec-independent.de/2009/05/blockd-mixing-ruby-smalltalk/</link>
		<comments>http://www.adztec-independent.de/2009/05/blockd-mixing-ruby-smalltalk/#comments</comments>
		<pubDate>Fri, 29 May 2009 17:42:18 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[blocktalk]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[hobbies]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=216</guid>
		<description><![CDATA[My new simple language, blockd, that I&#8217;ve mentioned in my last blog post is progressing quite nicely.
Since my last post a few days ago, I&#8217;ve worked on it quite a bit and I&#8217;ve got a first simple interpreter for it working.
For now, the interpreter is able to understand &#038; execute methodcalls on objects, anonymous methods [...]]]></description>
			<content:encoded><![CDATA[<p>My new simple language, <b>blockd</b>, that I&#8217;ve mentioned in my last blog post is progressing quite nicely.<br />
Since my last post a few days ago, I&#8217;ve worked on it quite a bit and I&#8217;ve got a first simple interpreter for it working.</p>
<p>For now, the interpreter is able to understand &#038; execute methodcalls on objects, anonymous methods (blocks &#038; procs in ruby) and some other minor stuff.</p>
<p>Heres a small example, that actually works now:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.adztec-independent.de/wp-content/plugins/wp-codebox/wp-codebox.php?p=216&amp;download=first_test.blk">first_test.blk</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2163"><td class="code" id="p216code3"><pre class="smalltalk" style="font-family:monospace;">y <span style="color: #000066; font-weight:bold;">=</span> <span style="">&#123;</span> |<span style="color: #00007f;">x</span>|
  <span style="color: #0000ff;">Console</span> puts: <span style="color: #00007f;">x</span>
  <span style="color: #0000ff;">Console</span> puts: <span style="">&#40;</span><span style="color: #00007f;">x</span> * <span style="color: #00007f;">x</span><span style="">&#41;</span>
<span style="">&#125;</span>
y call: <span style="color: #00007f;">10</span>
&nbsp;
m <span style="color: #000066; font-weight:bold;">=</span> <span style="">&#123;</span> |<span style="color: #00007f;">x y</span>|
  <span style="color: #0000ff;">Console</span> puts: <span style="">&#40;</span><span style="">&#40;</span><span style="color: #00007f;">x</span> upcase<span style="">&#41;</span> * <span style="color: #00007f;">y</span><span style="">&#41;</span>
<span style="">&#125;</span>
m call: <span style="color: #007f00; font-style: italic;">&quot;cool &quot;</span> y: <span style="color: #00007f;">10</span>
&nbsp;
square <span style="color: #000066; font-weight:bold;">=</span> <span style="">&#123;</span> |<span style="color: #00007f;">y</span>|
  y * <span style="color: #00007f;">y</span>
<span style="">&#125;</span>
cubic <span style="color: #000066; font-weight:bold;">=</span> <span style="">&#123;</span>|<span style="color: #00007f;">x</span>| <span style="">&#40;</span><span style="color: #00007f;">x</span> * <span style="color: #00007f;">x</span><span style="">&#41;</span> * <span style="color: #00007f;">x</span><span style="">&#125;</span>
&nbsp;
<span style="color: #7f0000;">3</span> times do |<span style="color: #00007f;">i</span>|
  <span style="color: #0000ff;">Console</span> puts: <span style="color: #00007f;">i</span>
end
&nbsp;
foo <span style="color: #000066; font-weight:bold;">=</span> <span style="">&#123;</span>
  <span style="color: #7f0000;">3</span> times <span style="">&#123;</span> |<span style="color: #00007f;">i</span>| <span style="color: #0000ff;">Console</span> puts: <span style="">&#40;</span><span style="color: #00007f;">square</span> call: <span style="color: #00007f;">i</span><span style="">&#41;</span> <span style="">&#125;</span>
<span style="">&#125;</span>
&nbsp;
<span style="color: #0000ff;">Console</span> puts: <span style="color: #007f00; font-style: italic;">&quot;--&quot;</span>
&nbsp;
foo call
&nbsp;
<span style="color: #7f0000;">10</span> times &amp;foo</pre></td></tr></table></div>

<p>This basically is equivalent to the following ruby code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.adztec-independent.de/wp-content/plugins/wp-codebox/wp-codebox.php?p=216&amp;download=first_test.rb">first_test.rb</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2164"><td class="code" id="p216code4"><pre class="ruby" style="font-family:monospace;">y = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> Console.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span>;Console.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>x.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
y.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>10<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
m = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x,y<span style="color:#006600; font-weight:bold;">|</span> Console.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>x.<span style="color:#9900CC;">upcase</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>y<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
m.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;cool &quot;</span>, 10<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
square = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>y<span style="color:#006600; font-weight:bold;">|</span> y.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>y<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
cubic = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> x.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
3.<span style="color:#9900CC;">times</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>Proc.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> Console.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
foo = <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span>3.<span style="color:#9900CC;">times</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>Proc.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> Console.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>square.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
Console.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;--&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
foo.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
10.<span style="color:#9900CC;">times</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>foo<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Now, to make this clear: The ruby code above is what the current interpreter actually executes. The way I&#8217;ve implemented it for now (and for simplicity only &#8211; just to get something working first) is, that it simply parses the blockd code and <i>translates</i> it into equivalent ruby code, which then gets executed via <i>eval</i> in ruby.<br />
Now I know, this isn&#8217;t the best way to do it, for several reasons:<br />
Normally, an interpreter executes the code it gets fed directly, expression for expression, as this is also the case for ruby. If you have an syntax error within the code that is evaluated, the interpreter usually notices this only at the moment it reaches that part of the code and tries to evaluate it. This isn&#8217;t the case for the current interpreter I wrote here. The reason I chose to do it this way, was that I wanted to get something working as possible. I do want to change it though later on, so that each expression gets executed on the fly, once it is parsed.</p>
<p>So for now, i evaluate the parsetree, and each expression node gets turned into a string of equivalent ruby code, that then gets saved in a global list (within a class called <i>Evaluator</i>). When the parser has done it&#8217;s job and all the values (strings of ruby code) of all expression nodes have been accumulated, i simply run ruby&#8217;s <i>eval</i> on it and at that point do the actual evaluation (and possibly get semantic errors here &#8211; like missing variables etc.).</p>
<p>I still need to implement some stuff regarding classes  &#038; modules, but I&#8217;m quite happy for now, since it wasn&#8217;t so hard as I had expected before. Once I have everything working, I&#8217;ll start to actually rewrite the parser in a way, that it evaluates &#038; executes code on the fly, expression per expression and not all of them at once at the end. This should also improve performance, which is obviously another downside of my current approach, since I have to wait for all expressions being parsed &#038; evaluated to appropriate ruby code first, before even beginning the actual evaluation process&#8230; </p>
<p>For anyone, who is interested, here is a simple benchmark of the code above:</p>
<p>The <b>blockd version</b> (executed with my current interpreter):</p>
<blockquote><p>
real	0m0.264s<br />
user	0m0.184s<br />
sys	0m0.072s
</p></blockquote>
<p>The <b>ruby version</b> of the equivalent code (generated by my parser):</p>
<blockquote><p>
real	0m0.021s<br />
user	0m0.008s<br />
sys	0m0.008s
</p></blockquote>
<p>As you can see, there&#8217;s quite a performance overhead. Although not really noticeable by a viewer, the numbers tell the story. So I expect quite an improvement in performance, once I&#8217;ll start rewriting the interpreter in the way I&#8217;ve mentioned above. Still cool though, if you ask me <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2009/05/blockd-mixing-ruby-smalltalk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Erlang: eFreeTPd</title>
		<link>http://www.adztec-independent.de/2009/03/programming-erlang-efreetpd/</link>
		<comments>http://www.adztec-independent.de/2009/03/programming-erlang-efreetpd/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 16:13:50 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[parallel programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=132</guid>
		<description><![CDATA[I&#8217;ve been learning Erlang for quite a while now and started working on a small Erlang-based Project: eFreeTPd &#8211; a free ftp daemon written in Erlang.
I&#8217;ve bought myself the Programming Erlang book by Joe Armstrong at Pragmatic Programmers, a very nice book to read if you&#8217;re interested in Erlang and parallel programming &#8211; or COP [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been learning <a href="http://www.erlang.org" target="_blank">Erlang</a> for quite a while now and started working on a small Erlang-based Project: <a href="http://github.com/bakkdoor/efreetpd" target="_blank">eFreeTPd</a> &#8211; a free ftp daemon written in Erlang.<br />
I&#8217;ve bought myself the <a href="http://www.pragprog.com/titles/jaerlang/programming-erlang" target="_blank">Programming Erlang</a> book by <a href="http://armstrongonsoftware.blogspot.com/" target="_blank">Joe Armstrong</a> at <a href="http://www.pragprog.com" target="_blank">Pragmatic Programmers</a>, a very nice book to read if you&#8217;re interested in Erlang and parallel programming &#8211; or COP (<a href="http://ll2.ai.mit.edu/talks/armstrong.pdf" target="_blank">Concurrency Oriented Programming</a>) &#8211; in general.</p>
<p>So yeah, Erlang is fun. It&#8217;s really easy to learn, if you ask me. If you know some Prolog, that&#8217;ll definately help a bit, since Erlang is influenced by it. But even if you&#8217;ve never heard of Prolog before, the language in itself is really small and easy. Just a few concepts you&#8217;ll have to learn including those of message passing style concurrency with processes instead of shared memory threads and mutable state. The syntax might seem weird at first, but I found this to be no real burden in the end.</p>
<p><a href="http://github.com/bakkdoor/efreetpd" target="_blank">eFreeTPd</a> isn&#8217;t finished yet, but I&#8217;ll keep up development. It shouldn&#8217;t take too long though until there&#8217;s a somewhat stable or functional version out <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next time I&#8217;ll write a little more on how <a href="http://github.com/bakkdoor/efreetpd" target="_blank">eFreeTPd</a> actually is implemented in terms of what design and overall structure is used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2009/03/programming-erlang-efreetpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clojure</title>
		<link>http://www.adztec-independent.de/2009/01/clojure/</link>
		<comments>http://www.adztec-independent.de/2009/01/clojure/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 00:56:55 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[recursion]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=123</guid>
		<description><![CDATA[




I&#8217;ve been trying out Clojure lately. Clojure is a new lisp dialect, that is hosted on the JVM and interoperates nicely with it. You can easily use Java methods, classes and libraries. I&#8217;ve been using it a little bit, watching some videos about it on blip.tv by it&#8217;s author, Rich Hickey, which really is a [...]]]></description>
			<content:encoded><![CDATA[<div class="mceTemp">
<dl class="wp-caption alignleft" style="width: 110px;">
<dt class="wp-caption-dt"><a href="http://www.clojure.org"><img title="Clojure logo" src="http://clojure.org/file/view/clojure-icon.gif" alt="Clojure logo" width="100" height="100" /></a></dt>
</dl>
</div>
<p>I&#8217;ve been trying out <a title="Clojure Website" href="http://www.clojure.org" target="_blank">Clojure</a> lately. Clojure is a new lisp dialect, that is hosted on the JVM and interoperates nicely with it. You can easily use Java methods, classes and libraries. I&#8217;ve been using it a little bit, watching some <a title="Clojure Channel on blip.tv" href="http://clojure.blip.tv" target="_blank">videos about it on blip.tv</a> by it&#8217;s author, Rich Hickey, which really is a brilliant guy. You should check them out as well, they give you a pretty good introduction to the language.</p>
<p>Compared to Common Lisp, which I really like allot as well, Clojure does feel a little bit more modern. For example, being not limited to reader support for lists, but also having maps and vectors (like arrays) as first class citizens, is really nice. And then theres the huge emphasis on multithreading support in a really nice way without locks and condition variables but with a stm (software transactional memory). Clojure is a functional language and focuses on immutability of data structures compared to Common Lisp, which also allows a more imperative style, if you want to. In Clojure, you&#8217;re forced to a functional style, which might seem like a downside at first, but which makes it possible to have some pretty neat features concerning multithreaded programming support. Since all the datastructures are immutable, there&#8217;s no need do use locks when having multiple threads sharing them. I suggest checking out the videos and to give Clojure a try. It seems very promising and it&#8217;s having quite a publicity boost right now. Just google for it, take a look on some mailinglists or checkout reddit etc. You&#8217;ll find plenty comments, links and blogposts about it (like this one <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p>
<p>So since I thought it&#8217;s always nice to try to port an existing little application from a language I already know to a new one I want to learn, I tried to port a very small programm <a title="CallToPower's website" href="http://www.calltopower.de" target="_blank">CallToPower</a>, a collegue from <a title="University of Osnabrück" href="http://www.uos.de" target="_blank">university</a>, wrote and <a title="Sysinfo.jar" href="http://calltopower.ca.funpic.de/stuff/blog/software/java/SysInfo.jar" target="_blank">posted on his website</a>. I pretty much copied it straightly to Clojure, changing some parts.</p>
<p>Now I know this might not be the best way to write it in Clojure. But it was my real first (although very small) programm in Clojure and I wanted to make it as close to the original, as possible. Basically, what it does is display some values of some system properties you can choose by pressing the appropriate. Nothing fancy, but it shows some Clojure related stuff pretty well.</p>
<p>So here&#8217;s the code, use it as you like:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p123code6'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1236"><td class="code" id="p123code6"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>ns sysinfo
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">gen-class</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">import</span> <span style="color: #66cc66;">&#40;</span>java<span style="color: #66cc66;">.</span>awt BorderLayout
		     GridLayout<span style="color: #66cc66;">&#41;</span>
	   <span style="color: #66cc66;">&#40;</span>java<span style="color: #66cc66;">.</span>awt<span style="color: #66cc66;">.</span>event ActionEvent
			   ActionListener<span style="color: #66cc66;">&#41;</span>
	   <span style="color: #66cc66;">&#40;</span>javax<span style="color: #66cc66;">.</span>swing JFrame
			JPanel
			JLabel
			JButton<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>def *x-coord* 30<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *y-coord* 30<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *width* 800<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *height* 230<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *prog-<span style="color: #b1b100;">name</span>* <span style="color: #ff0000;">&quot;SysInfo 1.0 [Clojure]&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *visible* true<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *resizable* true<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>def *frame* <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>def *label-property-mappings*
     <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">&quot;OS Name&quot;</span> <span style="color: #ff0000;">&quot;os.name&quot;</span><span style="color: #66cc66;">,</span>
       <span style="color: #ff0000;">&quot;OS Architecture&quot;</span> <span style="color: #ff0000;">&quot;os.arch&quot;</span><span style="color: #66cc66;">,</span>
       <span style="color: #ff0000;">&quot;Java Classpath&quot;</span> <span style="color: #ff0000;">&quot;java.class.path&quot;</span><span style="color: #66cc66;">,</span>
       <span style="color: #ff0000;">&quot;Java Version&quot;</span> <span style="color: #ff0000;">&quot;java.version&quot;</span><span style="color: #66cc66;">,</span>
       <span style="color: #ff0000;">&quot;Current working directory&quot;</span> <span style="color: #ff0000;">&quot;user.dir&quot;</span><span style="color: #66cc66;">,</span>
       <span style="color: #ff0000;">&quot;Resize to default&quot;</span> <span style="color: #ff0000;">&quot;Resize to default&quot;</span><span style="color: #66cc66;">,</span>
       <span style="color: #ff0000;">&quot;Clear&quot;</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn resize-frame
  <span style="color: #66cc66;">&#91;</span>frame a b awidth bheight<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span>doto frame
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setBounds a b awidth bheight<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn set-label-text <span style="color: #66cc66;">&#91;</span>label text<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span>doto label
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setText text<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn button-listener
  <span style="color: #ff0000;">&quot;Returns a ActionListener, which sets the text of the content label (label-content)
  to the appropriate system property (System.getProperty).&quot;</span>
  <span style="color: #66cc66;">&#91;</span>property label frame<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span>proxy <span style="color: #66cc66;">&#91;</span>ActionListener<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span>actionPerformed <span style="color: #66cc66;">&#91;</span>evt<span style="color: #66cc66;">&#93;</span>
		     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>system-property-<span style="color: #b1b100;">value</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> System getProperty property<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>equalsIgnoreCase property <span style="color: #ff0000;">&quot;Resize to default&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>equalsIgnoreCase property <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			   <span style="color: #66cc66;">&#40;</span>set-label-text label <span style="color: #66cc66;">&#40;</span>str <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getActionCommand evt<span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> system-property-<span style="color: #b1b100;">value</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			   <span style="color: #66cc66;">&#40;</span>set-label-text label property<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			 <span style="color: #66cc66;">&#40;</span>resize-frame frame *x-coord* *y-coord* *width* *height*<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> doto-each
  <span style="color: #ff0000;">&quot;Macro, that works like doto-macro, only that it does it for each object in objects.
  varname is bound to each object in turn inside of the body (forms) and can be used to access the current
  object, if needed.&quot;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span>varname <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&amp;</span> objects<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&amp;</span> forms<span style="color: #66cc66;">&#93;</span>
  `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span>
     ~@<span style="color: #66cc66;">&#40;</span>map <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#91;</span>f<span style="color: #66cc66;">&#93;</span> `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>~varname ~f<span style="color: #66cc66;">&#93;</span>
		       <span style="color: #66cc66;">&#40;</span>doto ~f
			 ~@forms<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	    objects<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> add-each
  <span style="color: #ff0000;">&quot;Macro, that calls .add on to-object with each object in objects.&quot;</span>
  <span style="color: #66cc66;">&#91;</span>to-object <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&amp;</span> objects<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>
  `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span>
     ~@<span style="color: #66cc66;">&#40;</span>map <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#91;</span>o<span style="color: #66cc66;">&#93;</span> `<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>add ~to-object ~o<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	    objects<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn create-new-sysinfo-window
  <span style="color: #ff0000;">&quot;Creates the main form and returns it. Mainly GUI-related stuff (javax.swing).&quot;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>frame <span style="color: #66cc66;">&#40;</span>JFrame<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Adztec-Independent.de: SysInfo Clojure-style!&quot;</span><span style="color: #66cc66;">&#41;</span>
	panel-header <span style="color: #66cc66;">&#40;</span>JPanel<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#41;</span>
	panel-main <span style="color: #66cc66;">&#40;</span>JPanel<span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span>BorderLayout<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	panel-left <span style="color: #66cc66;">&#40;</span>JPanel<span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span>GridLayout<span style="color: #66cc66;">.</span> <span style="color: #cc66cc;">6</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	panel-south <span style="color: #66cc66;">&#40;</span>JPanel<span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span>GridLayout<span style="color: #66cc66;">.</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #808080; font-style: italic;">;; labels</span>
	label-header <span style="color: #66cc66;">&#40;</span>JLabel<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;System Information&quot;</span><span style="color: #66cc66;">&#41;</span>
	label-blank <span style="color: #66cc66;">&#40;</span>JLabel<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>
	label-content <span style="color: #66cc66;">&#40;</span>JLabel<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>
	label-adztec-indep <span style="color: #66cc66;">&#40;</span>JLabel<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;by www.adztec-independent.de&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setHorizontalAlignment label-blank <span style="color: #66cc66;">&#40;</span>JLabel/CENTER<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setHorizontalAlignment label-adztec-indep <span style="color: #66cc66;">&#40;</span>JLabel/CENTER<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">;; buttons</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>btn-java-cp <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Java Classpath&quot;</span><span style="color: #66cc66;">&#41;</span>
	  btn-java-version <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Java Version&quot;</span><span style="color: #66cc66;">&#41;</span>
	  btn-os-<span style="color: #b1b100;">name</span> <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;OS Name&quot;</span><span style="color: #66cc66;">&#41;</span>
	  btn-os-arch <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;OS Architecture&quot;</span><span style="color: #66cc66;">&#41;</span>
	  btn-current-working-dir <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Current working directory&quot;</span><span style="color: #66cc66;">&#41;</span>
	  btn-resize-to-default <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Resize to default&quot;</span><span style="color: #66cc66;">&#41;</span>
	  btn-clear-all <span style="color: #66cc66;">&#40;</span>JButton<span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Clear&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span>
	<span style="color: #808080; font-style: italic;">;; add button-listener to all buttons</span>
	<span style="color: #66cc66;">&#40;</span>doto-each  <span style="color: #66cc66;">&#91;</span>btn <span style="color: #66cc66;">&#91;</span>btn-java-cp
			  btn-java-version
			  btn-os-<span style="color: #b1b100;">name</span>
			  btn-os-arch
			  btn-current-working-dir
			  btn-resize-to-default
			  btn-clear-all<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
		      <span style="color: #808080; font-style: italic;">;; add listener to button</span>
		    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>addActionListener
		     <span style="color: #66cc66;">&#40;</span>button-listener <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">get</span> *label-property-mappings* <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getText btn<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> label-content frame<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">;; add buttons to panel</span>
	<span style="color: #66cc66;">&#40;</span>add-each panel-left
		  <span style="color: #66cc66;">&#91;</span>btn-java-cp
		   btn-java-version
		   btn-os-<span style="color: #b1b100;">name</span>
		   btn-os-arch
		   btn-current-working-dir<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span>add-each panel-south
		  <span style="color: #66cc66;">&#91;</span>btn-resize-to-default
		   btn-clear-all<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">;; add labels to panel</span>
	<span style="color: #66cc66;">&#40;</span>add-each panel-header
		  <span style="color: #66cc66;">&#91;</span>label-header
		   label-blank<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>add panel-south label-adztec-indep<span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">;; pack on frame</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>content-pane <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getContentPane frame<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	  <span style="color: #66cc66;">&#40;</span>add-each content-pane
		    <span style="color: #66cc66;">&#91;</span>panel-main
		     label-content<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>doto content-pane
	    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>add BorderLayout/NORTH panel-header<span style="color: #66cc66;">&#41;</span>
	    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>add BorderLayout/WEST panel-left<span style="color: #66cc66;">&#41;</span>
	    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>add BorderLayout/SOUTH panel-south<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span>doto frame
	  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>pack<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setTitle *prog-<span style="color: #b1b100;">name</span>*<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>resize-frame *x-coord* *y-coord* *width* *height*<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setVisible *visible*<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setResizable *resizable*<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>setDefaultCloseOperation JFrame/HIDE_ON_CLOSE<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    frame<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">;; return frame</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn -main
  <span style="color: #ff0000;">&quot;Main function. Gets called by the system, if used as an executable .jar file.&quot;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>*frame* <span style="color: #66cc66;">&#40;</span>create-new-sysinfo-window<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
       <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> Thread <span style="color: #66cc66;">&#40;</span>sleep <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2009/01/clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lisp labels and anonymous functions</title>
		<link>http://www.adztec-independent.de/2008/12/lisp-labels-and-anonymous-functions/</link>
		<comments>http://www.adztec-independent.de/2008/12/lisp-labels-and-anonymous-functions/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 02:08:20 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[special operator]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=79</guid>
		<description><![CDATA[I was playing around with Lisp some more in the last few weeks, and today i came across a little problem with anonymous functions (or lambdas, if you want to).
The problem with anonymous lambda functions is, that they can&#8217;t call themselves recursively, since &#8211; well they&#8217;re anonymous and hence don&#8217;t have a name. To get [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with Lisp some more in the last few weeks, and today i came across a little problem with anonymous functions (or lambdas, if you want to).</p>
<p>The problem with anonymous lambda functions is, that they can&#8217;t call themselves recursively, since &#8211; well they&#8217;re anonymous and hence don&#8217;t have a name. To get passed this problem, you can let it have an additional function parameter which it will call in place where the recursion would normally take place.</p>
<p>An example for a reverse function, which reverses the elements of its argument (a list) with the help of an accumulator list (which holds the reversed list) could be written like this, without using an additional function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code10'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p7910"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p79code10"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> myreverse <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&amp;</span>optional <span style="color: #66cc66;">&#40;</span>acc <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>head <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
      <span style="color: #66cc66;">&#40;</span>head
       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
	 <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">atom</span> head<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>myreverse rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> head acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	 <span style="color: #66cc66;">&#40;</span>t
	  <span style="color: #66cc66;">&#40;</span>myreverse rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>myreverse head<span style="color: #66cc66;">&#41;</span> acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>t
       acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>But, as you can see, the accumulator list is part of the function&#8217;s argument list, although optional. To make this function a little bit &#8217;safer&#8217;, it shouldn&#8217;t be part of the &#8216;public interface&#8217; of the function. So you&#8217;d probably come up with something like this, where you&#8217;d use an anonymous helper function, which takes the additional accumulator list and returns it when it&#8217;s done reversing the original list:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code11'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p7911"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p79code11"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> myreverse <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>reverse-acc #'<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>func <span style="color: #b1b100;">list</span> acc<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>head <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span>head
				 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">atom</span> head<span style="color: #66cc66;">&#41;</span>
					<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> func func rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> head acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				       <span style="color: #66cc66;">&#40;</span>t
					<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> func func rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> func func head <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span> acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#40;</span>t
				 acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> reverse-acc reverse-acc <span style="color: #b1b100;">list</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>But, as you can see, since anonymous functions can&#8217;t call themselves recursively, you need to give it another extra parameter, a function object, which actually gets filled with the anonymous function itself, so it can call itself inside its body. But, fortunately, theres an even better version how to do exactly this in lisp: With the labels special operator, which defines local functions with a given name (like normal functions) which can then get called inside the function body itself and in the body-form of the macro:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code12'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p7912"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p79code12"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> myreverse <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>labels <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>myreverse-acc <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> acc<span style="color: #66cc66;">&#41;</span>
	     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>head <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span>head
		      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">atom</span> head<span style="color: #66cc66;">&#41;</span>
			     <span style="color: #66cc66;">&#40;</span>myreverse-acc rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> head acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			    <span style="color: #66cc66;">&#40;</span>t
			     <span style="color: #66cc66;">&#40;</span>myreverse-acc rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>myreverse-acc head <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span> acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		     <span style="color: #66cc66;">&#40;</span>t
		      acc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>myreverse-acc <span style="color: #b1b100;">list</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>As you can see, this version is nicer than the first or the second, since it hides the fact, that the reverse function uses an accumulator list and that it is also easier to understand, since you can use an actual name for the function instead of passing the function as an argument to itself, in ordner to make a recursive call. So basically, you can think of a function defined with the labels special operator as a local defun, which I think is really nice. <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2008/12/lisp-labels-and-anonymous-functions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Language creation</title>
		<link>http://www.adztec-independent.de/2008/12/language-creation/</link>
		<comments>http://www.adztec-independent.de/2008/12/language-creation/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 21:41:38 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[hobbies]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[meta-programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=76</guid>
		<description><![CDATA[ 

I recently started thinking about creating a programming language from scratch, but obviously heavily inspired by existing programming languages out there.
I don&#8217;t have anything concrete yet but these are the main principles I came up with for the language:

Somewhat functional (but not purely functional). So side-effects should be more or less easily possible within non side-effecting [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<div>
<p>I recently started thinking about creating a programming language from scratch, but obviously heavily inspired by existing programming languages out there.</p>
<p>I don&#8217;t have anything concrete yet but these are the main principles I came up with for the language:</p>
<ul>
<li>Somewhat functional (but not purely functional). So side-effects should be more or less easily possible within non side-effecting code. Mainly for reasons regarding the process of actually building the compiler / interpreter and that it should be a dynamic language. Especially the last point makes it pretty obvious that since there is no static typechecking, making  it purely functional would be kind of hard to realise (although possible i guess). </li>
<li>Garbage-collected / automatic memory management. Kind of makes sense with a functional language and who really wants another assembly-like, low-level language?</li>
<li>An easy way to extend the language in itself (as in Lisp, for example, with macros or some similar meta-programming capability).</li>
<li>Dynamically typed (like Lisp or Ruby for example)</li>
<li>Small, in the sense that the language itself should not be bloated and most of the value of it shouldn&#8217;t be part of the language itself, but implemented in it. By that I don&#8217;t only mean the standard library, where this usually is the case already, but also those things, often considered part of the language (or &#8220;built-in&#8221;) in other languages. Haskell is a good example of operators and data types not being tied completely into the language, but rather implemented in it. A good example is the Boolean data type, which is merely defined in Haskell itself (and if it hadn&#8217;t been, it would be trivial to come up with your own). This works because Haskell uses some very nice pattern matching with its algebraic datatypes and I could imagine something similar for my language.</li>
</ul>
<p>That are my main concerns this far. Obviously theres still much to decide, mainly syntax and semantics. Compelling are Haskell&#8217;s typesystem with its really powerful, yet simple datatypes and pattern matching. On the other hand there&#8217;s Lisp with its macros and Ruby with its also powerful meta-programming mechanisms.</p>
<p>Let&#8217;s see, where this will go <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2008/12/language-creation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

