<?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; recursion</title>
	<atom:link href="http://www.adztec-independent.de/tag/recursion/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>Parser generation with Ruby</title>
		<link>http://www.adztec-independent.de/2009/05/parser-generation-with-ruby/</link>
		<comments>http://www.adztec-independent.de/2009/05/parser-generation-with-ruby/#comments</comments>
		<pubDate>Wed, 27 May 2009 00:12:25 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[blocktalk]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[hobbies]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[meta-programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=201</guid>
		<description><![CDATA[I&#8217;ve started to play a little with Treetop, a parser generator library for Ruby.
Why? you might ask. While I&#8217;ve been dreaming of my own programming languages and designing them for quite some time now, I never really managed to actually get beyond the design-phase. I&#8217;ve come up with several language designs in the past, each [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started to play a little with <a href="http://treetop.rubyforge.org">Treetop</a>, a parser generator library for Ruby.<br />
Why? you might ask. While I&#8217;ve been dreaming of my own programming languages and designing them for quite some time now, I never really managed to actually get beyond the design-phase. I&#8217;ve come up with several language designs in the past, each time getting closer to something that I think really could work (which doesn&#8217;t mean, that it actually could be useful or &#8216;good&#8217; &#8211; if that even makes sense).<br />
While I&#8217;ve been looking at many different languages in the past, I&#8217;ve found the dynamic, object-oriented and functional  high-level languages to be most interesting &#038; fun to work with. Naturally, after working with Ruby alot, I&#8217;ve started looking a little bit at Smalltalk and how it differs to Ruby.</p>
<p>Inspired by what Smalltalk and Ruby have to give, I started designing my own language, heavily influenced by those two great, very dynamic, truly object-oriented programming languages and came up with a quite simple language named <b>blockd</b>.</p>
<p>The name is based upon the main principle of the language: Everything is an object, and in the end, all code is defined within blocks &#8211; that are ruby / smalltalk like blocks. Naming these blocks is done via simple assignment. So instead of having a huge amount of keywords, the language itself is pretty simple, because all we really need is a way to describe assignments, instantiate objects and easily create blocks to pass to methods or use in an assignment.</p>
<p>So in contrast to Ruby, where there are procs, lambdas and blocks, blockd only knows blocks, which basically behave like Smalltalk like blocks &#8211; they simply are anonymous procedures / blocks of code (or functions, if you want to call them that &#8211; although not pure as in Haskell).</p>
<p>The syntax is a mix of Ruby&#8217;s and Smalltalk&#8217;s with some minor tweaks I thought would be cool (or not? I don&#8217;t know <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).<br />
To give you an example of how the language looks, here is a small snippet of some sample code, that actually doesn&#8217;t work yet but might do so in the future <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </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=201&amp;download=sample.blk">sample.blk</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2012"><td class="code" id="p201code2"><pre class="lisp" style="font-family:monospace;"># this is just for demonstration
# there probably won't be the need to require the console module from the
# standard library every time you want to print something to the screen <span style="color: #808080; font-style: italic;">;)</span>
System require<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">&quot;console&quot;</span>
&nbsp;
# we support ruby-style blocks with <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">...</span> end <span style="color: #b1b100;">and</span> curly braces <span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">...</span> <span style="color: #66cc66;">&#125;</span>
File open<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">&quot;test.txt&quot;</span> mode<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">&quot;w&quot;</span> <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">|</span>f<span style="color: #66cc66;">|</span>
  f puts<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">&quot;what's up, dog?!&quot;</span>
  f puts<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">&quot;crazy shit, yo!&quot;</span>
  f puts<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">&quot;hahaha!!&quot;</span>
end
&nbsp;
10 to<span style="color: #66cc66;">:</span> 0 <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">|</span>i<span style="color: #66cc66;">|</span>
  Console puts<span style="color: #66cc66;">:</span> <span style="color: #555;">i</span>
end
&nbsp;
i <span style="color: #66cc66;">=</span> 0
<span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">&lt;</span> 10<span style="color: #66cc66;">&#41;</span> while_true<span style="color: #66cc66;">:</span> <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">|</span>i<span style="color: #66cc66;">|</span>
  Console puts<span style="color: #66cc66;">:</span> <span style="color: #555;">i</span>
  i incr
end
&nbsp;
numbers <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#91;</span>1<span style="color: #66cc66;">,</span>2<span style="color: #66cc66;">,</span>3<span style="color: #66cc66;">,</span>4<span style="color: #66cc66;">,</span>5<span style="color: #66cc66;">&#93;</span> select<span style="color: #66cc66;">:</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">|</span>i<span style="color: #66cc66;">|</span> i <span style="color: #66cc66;">&lt;</span> 3<span style="color: #66cc66;">&#125;</span>
numbers each<span style="color: #66cc66;">:</span> <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">|</span>i<span style="color: #66cc66;">|</span>
  puts i
end
&nbsp;
<span style="color: #66cc66;">&#40;</span>1 <span style="color: #66cc66;">..</span> 100<span style="color: #66cc66;">&#41;</span> each<span style="color: #66cc66;">:</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">|</span>i<span style="color: #66cc66;">|</span> Console puts<span style="color: #66cc66;">:</span> <span style="color: #555;">i</span><span style="color: #66cc66;">&#125;</span>
&nbsp;
squares <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>1 <span style="color: #66cc66;">..</span> 100<span style="color: #66cc66;">&#41;</span> collect<span style="color: #66cc66;">:</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">|</span>i<span style="color: #66cc66;">|</span> i<span style="color: #66cc66;"> * </span>i<span style="color: #66cc66;">&#125;</span>
&nbsp;
# define a square method
square <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">|</span>x<span style="color: #66cc66;">|</span>
  x<span style="color: #66cc66;"> * </span>x
<span style="color: #66cc66;">&#125;</span>
&nbsp;
# <span style="color: #b1b100;">or</span> like this<span style="color: #66cc66;">:</span>
<span style="color: #b1b100;">abs</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">|</span>num<span style="color: #66cc66;">|</span>
  <span style="color: #66cc66;">&#40;</span>num <span style="color: #66cc66;">&gt;</span> 0<span style="color: #66cc66;">&#41;</span> if_true <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> num
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  num<span style="color: #66cc66;"> * </span>-<span style="color: #cc66cc;">1</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;m still tweaking the syntax and haven&#8217;t decided upon all things completely yet, but I guess I&#8217;ve found the pretty basic &#8220;feel&#8221; of it.</p>
<p>While I haven&#8217;t shown you any code that defines a class or modules, it still does show a little of the languages syntax.  I&#8217;ve started the parser today and it successfully parses the code above, meaning, that since the syntax isn&#8217;t too complicated, I expect to be able to parse all the remaining stuff (classes &#038; modules and some minor other things) pretty soon. I then intend to start writing the actual implementation &#8211; an interpreter written in Ruby. While I could come up with my own runtime, class library etc, I want to make use of the Ruby infrastructure as much as possible. For one reason, it makes it easier to actually implement something useful, on the other hand, since the language is very close to Ruby&#8217;s object model and semantics, I hope I can use most of Ruby&#8217;s code directly. This also would mean, that the interpreter could also run on other Ruby implementations like JRuby, IronRuby etc. And maybe, some day, it could also run natively compiled with the Ruby compiler I&#8217;ve been working on recently as well &#8211; but that&#8217;s still far into the future, since the compiler isn&#8217;t finished yet.</p>
<p>I guess that&#8217;s it for now. More to come soon <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/parser-generation-with-ruby/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('p123code4'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1234"><td class="code" id="p123code4"><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('p79code8'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p798"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p79code8"><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('p79code9'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p799"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p79code9"><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('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;">&#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>
	</channel>
</rss>

