<?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; common lisp</title>
	<atom:link href="http://www.adztec-independent.de/tag/common-lisp/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>Sun, 21 Mar 2010 23:27:44 +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>Lisp Screencast 01: Macros</title>
		<link>http://www.adztec-independent.de/2009/01/lisp-screencast-01-macros/</link>
		<comments>http://www.adztec-independent.de/2009/01/lisp-screencast-01-macros/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 03:04:25 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Lisp Screencast]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[meta-programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=115</guid>
		<description><![CDATA[I&#8217;ll post some stuff and pictures of the congress soon, but I wanted to make another post first.
I&#8217;ve been programming Lisp for a little while now and always have been looking for some video tutorials (or screencasts) about Common Lisp or Lisp  programming in general but haven&#8217;t found so many.
Also doing some Ruby stuff, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll post some stuff and pictures of the congress soon, but I wanted to make another post first.</p>
<p>I&#8217;ve been programming Lisp for a little while now and always have been looking for some video tutorials (or screencasts) about Common Lisp or Lisp  programming in general but haven&#8217;t found so many.<br />
Also doing some Ruby stuff, I always enjoyed the huge amount of videos online and thought that there should be more Lisp related screencasts as well.</p>
<p>So, I thought about starting my own. And here it is <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can download the Quicktime file here: <a href="http://www.adztec-independent.de/wp-content/screencast/Lisp%20Screencast%20-%2001%20-%20Macros.mov">Lisp Screencast #01: Macros</a></p>
<p>Or also watch it on my <a href="http://bakkdoor.blip.tv/" target="_blank">Blip.tv channel</a>:</p>
<p><object width="500" height="500" data="http://blip.tv/play/gq855LcRktwZ" type="application/x-shockwave-flash"><param name="src" value="http://blip.tv/play/gq855LcRktwZ" /><param name="allowfullscreen" value="true" /></object></p>
<p>Any comments? Feel free to send me a mail or post a comment here.</p>
<p>I&#8217;ll try to make this a regular thing for the future. Any topic suggestions are also welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2009/01/lisp-screencast-01-macros/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.adztec-independent.de/wp-content/screencast/Lisp%20Screencast%20-%2001%20-%20Macros.mov" length="56134847" type="video/quicktime" />
		</item>
		<item>
		<title>Lisp macros revisited</title>
		<link>http://www.adztec-independent.de/2008/12/lisp-macros-revisited/</link>
		<comments>http://www.adztec-independent.de/2008/12/lisp-macros-revisited/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 10:56:14 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[special operator]]></category>
		<category><![CDATA[tagbody]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=90</guid>
		<description><![CDATA[Since my first posts on my own little control macros (while, foreach etc.) I&#8217;ve learned quite a bit and so here are my revised versions of some of them, since not all of them would work outside of an interpreter, since they were recursive macros.
A better, and also non recursive way to write macros is [...]]]></description>
			<content:encoded><![CDATA[<p>Since my first posts on my own little control macros (while, foreach etc.) I&#8217;ve learned quite a bit and so here are my revised versions of some of them, since not all of them would work outside of an interpreter, since they were recursive macros.<br />
A better, and also non recursive way to write macros is to either use exisiting macros (as done with my for macro) or for example by using the tagbody &#038; go constructs of lisp (similar to a goto in C):</p>
<p><strong>new while macro</strong></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('p90code4'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p904"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p90code4"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; while macro with tagbody &amp; go.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> while-new <span style="color: #66cc66;">&#40;</span>condition <span style="color: #66cc66;">&amp;</span>body body<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>tag-<span style="color: #b1b100;">name</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">gensym</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>tagbody
      <span style="color: #66cc66;">,</span>tag-<span style="color: #b1b100;">name</span>
      <span style="color: #66cc66;">,</span>@body
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">,</span>condition
	<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">go</span> <span style="color: #66cc66;">,</span>tag-<span style="color: #b1b100;">name</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></pre></td></tr></table></div>

<p><em>Thanks again to the anonymous commenter &#8216;foo&#8217;, who made it clear, that the previous version (without gensymed-symbols) could make trouble in the case of a caller having symbols defined with the same name (in this case tag-name).</p>
<p>I also changed the foreach-macro to use gensymed symbols:</em></p>
<p><strong>new foreach macro</strong></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('p90code5'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p905"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p90code5"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; foreach macro with tagbody &amp; go.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> foreach-new <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>var <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>body body<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>tmp-<span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">gensym</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>start-tag <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">gensym</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;">let</span>* <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>tmp-<span style="color: #b1b100;">list</span> <span style="color: #66cc66;">,</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>var <span style="color: #b1b100;">nil</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: #66cc66;">,</span>tmp-<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>tagbody
	  <span style="color: #66cc66;">,</span>start-tag
	  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null</span> <span style="color: #66cc66;">,</span>tmp-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span>
	      <span style="color: #b1b100;">nil</span>
	      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
		<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> <span style="color: #66cc66;">,</span>var <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">,</span>tmp-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> rest <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> <span style="color: #66cc66;">,</span>tmp-<span style="color: #b1b100;">list</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;">,</span>var
		  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span> <span style="color: #66cc66;">,</span>@body
			 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> <span style="color: #66cc66;">,</span>tmp-<span style="color: #b1b100;">list</span> rest<span style="color: #66cc66;">&#41;</span>
			 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">go</span> <span style="color: #66cc66;">,</span>start-tag<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</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><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><strong>new until macro</strong></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('p90code6'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p906"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p90code6"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; until macro reusing new while macro.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> until-new <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&amp;</span>body body<span style="color: #66cc66;">&#41;</span>
  `<span style="color: #66cc66;">&#40;</span>while-new <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">,</span><span style="color: #b1b100;">cond</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">,</span>@body<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Also, thanks to &#8216;foo&#8217;, who pointed this out in some comments.<br />
I&#8217;ve known about this fact for little while already, but haven&#8217;t thought about posting it here. Since some people might be reading this and wondering, why they don&#8217;t seem to work, they now should have some working samples. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2008/12/lisp-macros-revisited/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>3</slash:comments>
		</item>
		<item>
		<title>easter-date.lisp</title>
		<link>http://www.adztec-independent.de/2008/11/easter-datelisp/</link>
		<comments>http://www.adztec-independent.de/2008/11/easter-datelisp/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 22:36:11 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=58</guid>
		<description><![CDATA[Based on the algorithm described by CallToPower on his webblog here&#8217;s a lisp version of it:

?View Code LISP1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
&#40;defun easter-date-for-year &#40;year &#38;optional &#38;key &#40;use-date-name t&#41;&#41;
  &#40;let &#40;&#40;golden-year &#40;+ 1 &#40;mod year 19&#41;&#41;&#41;
	&#40;century &#40;+ &#40;/ year 100&#41; 1&#41;&#41;&#41;
    &#40;let &#40;&#40;skipped-leap-years &#40;- &#40;/ &#40;* 3 century&#41; 4&#41; 12&#41;&#41;
	  &#40;correction-factor &#40;- &#40;/ &#40;+ &#40;* [...]]]></description>
			<content:encoded><![CDATA[<p>Based on the algorithm described by CallToPower on his <a href="http://www.calltopower.de">webblog</a> here&#8217;s a lisp version of it:</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('p58code14'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p5814"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code" id="p58code14"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> easter-date-for-year <span style="color: #66cc66;">&#40;</span>year <span style="color: #66cc66;">&amp;</span>optional <span style="color: #66cc66;">&amp;</span>key <span style="color: #66cc66;">&#40;</span>use-date-<span style="color: #b1b100;">name</span> t<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>golden-year <span style="color: #66cc66;">&#40;</span>+ 1 <span style="color: #66cc66;">&#40;</span>mod year 19<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span>century <span style="color: #66cc66;">&#40;</span>+ <span style="color: #66cc66;">&#40;</span>/ year 100<span style="color: #66cc66;">&#41;</span> 1<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;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>skipped-leap-years <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>/ <span style="color: #66cc66;">&#40;</span>* 3 century<span style="color: #66cc66;">&#41;</span> 4<span style="color: #66cc66;">&#41;</span> 12<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>correction-factor <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>/ <span style="color: #66cc66;">&#40;</span>+ <span style="color: #66cc66;">&#40;</span>* 8 century<span style="color: #66cc66;">&#41;</span> 5<span style="color: #66cc66;">&#41;</span> 25<span style="color: #66cc66;">&#41;</span> 5<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;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>d <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>/ <span style="color: #66cc66;">&#40;</span>* 5 year<span style="color: #66cc66;">&#41;</span> 4<span style="color: #66cc66;">&#41;</span> skipped-leap-years 10<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	    <span style="color: #66cc66;">&#40;</span>epac <span style="color: #66cc66;">&#40;</span>mod <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>+ <span style="color: #66cc66;">&#40;</span>* 11 golden-year<span style="color: #66cc66;">&#41;</span> 20 correction-factor<span style="color: #66cc66;">&#41;</span> skipped-leap-years<span style="color: #66cc66;">&#41;</span> 30<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;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> epac 25<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> golden-year 11<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> epac 24<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	    <span style="color: #66cc66;">&#40;</span>incf epac<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>n <span style="color: #66cc66;">&#40;</span>- 44 epac<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>month <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>day-of-month <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;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> n 21<span style="color: #66cc66;">&#41;</span>
	      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> n <span style="color: #66cc66;">&#40;</span>+ 30 n<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;">setf</span> n <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>+ n 7<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>mod <span style="color: #66cc66;">&#40;</span>+ d n<span style="color: #66cc66;">&#41;</span> 7<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;">cond</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> n 31<span style="color: #66cc66;">&#41;</span>
		 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> month
		       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> use-date-<span style="color: #b1b100;">name</span>
			   'APRIL
			   4<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> day-of-month <span style="color: #66cc66;">&#40;</span>- n 31<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;">setf</span> month
		       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> use-date-<span style="color: #b1b100;">name</span>
			   'MARCH
			   3<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> day-of-month n<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;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>formatted-date <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> use-date-<span style="color: #b1b100;">name</span>
				    <span style="color: #ff0000;">&quot;~a. ~a ~a&quot;</span>
				    <span style="color: #ff0000;">&quot;~a.~a.~a&quot;</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>format <span style="color: #b1b100;">nil</span> 
		    <span style="color: #66cc66;">&#40;</span>concatenate 'string <span style="color: #ff0000;">&quot;Easter date: &quot;</span> formatted-date<span style="color: #66cc66;">&#41;</span> 
		    <span style="color: #66cc66;">&#40;</span>round day-of-month<span style="color: #66cc66;">&#41;</span> month year<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;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2008/11/easter-datelisp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lisp macros part 2</title>
		<link>http://www.adztec-independent.de/2008/11/lisp-macros-part-2/</link>
		<comments>http://www.adztec-independent.de/2008/11/lisp-macros-part-2/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 15:56:36 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[meta-programming]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=36</guid>
		<description><![CDATA[I&#8217;ve been playing a little more with macros and came up with a foreach-loop, similar to those used in Java or C#.
It basically does the same as the predefined dolist-macro, but oh well  
foreach macro

?View Code LISP1
2
3
4
5
6
7
8
9
10
;; foreach-loop, similar to those in Java or C#
;; example: (foreach (x '(1 2 3))
;;       [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing a little more with macros and came up with a foreach-loop, similar to those used in Java or C#.</p>
<p>It basically does the same as the predefined dolist-macro, but oh well <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>foreach macro</strong></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('p36code17'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p3617"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p36code17"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; foreach-loop, similar to those in Java or C#</span>
<span style="color: #808080; font-style: italic;">;; example: (foreach (x '(1 2 3))</span>
<span style="color: #808080; font-style: italic;">;;                               (print x))</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> foreach <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>var <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>body body<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><span style="color: #66cc66;">,</span>var <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">,</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: #66cc66;">,</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;">if</span> <span style="color: #66cc66;">,</span>var
	<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
	  <span style="color: #66cc66;">,</span>@body
	  <span style="color: #66cc66;">&#40;</span>foreach <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>var rest<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span>@body<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</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>I&#8217;ve also come up with my own file-handling macro, similar to the predefined with-open-file:</p>
<p><strong>with-file macro</strong></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('p36code18'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p3618"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p36code18"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; can be used like with-open-file macro</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> with-file <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>filestream-var filename <span style="color: #66cc66;">&amp;</span>optional <span style="color: #66cc66;">&amp;</span>key <span style="color: #66cc66;">&#40;</span>if-exists <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>direction <span style="color: #66cc66;">:</span><span style="color: #555;">input</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>body body<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><span style="color: #66cc66;">,</span>filestream-var <span style="color: #66cc66;">&#40;</span>open <span style="color: #66cc66;">,</span>filename <span style="color: #66cc66;">:</span><span style="color: #555;">direction</span> <span style="color: #66cc66;">,</span>direction <span style="color: #66cc66;">:</span><span style="color: #555;">if-exists</span> <span style="color: #66cc66;">,</span>if-exists<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">,</span>@body
    <span style="color: #66cc66;">&#40;</span>close <span style="color: #66cc66;">,</span>filestream-var<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>At first macros seemed to be something complicated, but once I&#8217;ve started reimplementing some of the standard macros and also making up my own custom ones, it really got much clearer to me how they work and why they are so important. Especially the with-file macro gives you an idea of whats possible with macros. Abstracting away the pattern of opening a file, doing something and then closing it again is just really nice, since you won&#8217;t ever forget to close it again, if you stick with using the macro.</p>
<p>I&#8217;ll try to come up with some more soon. <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next big thing on my agenda is some file in- and output as well as CLOS, the powerful Common Lisps Object System.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2008/11/lisp-macros-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating standard control structures in common lisp</title>
		<link>http://www.adztec-independent.de/2008/11/creating-standard-control-structures-in-common-lisp/</link>
		<comments>http://www.adztec-independent.de/2008/11/creating-standard-control-structures-in-common-lisp/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 16:59:14 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[meta-programming]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=29</guid>
		<description><![CDATA[I&#8217;ve been playing around with (and also learning) common lisp recently and found its macro system very intriguing. So I started to implement some standard imperative control structures that closely resemble those found in most imperative mainstream programming languages like Java or C.
Here&#8217;s what I&#8217;ve done so far:
while macro:

?View Code LISP1
2
3
4
5
6
7
8
;; example:
;; (defparameter x 0)
;; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with (and also learning) common lisp recently and found its macro system very intriguing. So I started to implement some standard imperative control structures that closely resemble those found in most imperative mainstream programming languages like Java or C.</p>
<p>Here&#8217;s what I&#8217;ve done so far:</p>
<p><strong>while macro:</strong></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('p29code22'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2922"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p29code22"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; example:</span>
<span style="color: #808080; font-style: italic;">;; (defparameter x 0)</span>
<span style="color: #808080; font-style: italic;">;; (while (&lt; x 10) (print x) (incf x)) ;; output numbers 0 - 9.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> while <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&amp;</span>body body<span style="color: #66cc66;">&#41;</span>
  `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">,</span><span style="color: #b1b100;">cond</span> 
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span> <span style="color: #66cc66;">,</span>@body 
	   <span style="color: #66cc66;">&#40;</span>while <span style="color: #66cc66;">,</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">,</span>@body<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><strong>until macro</strong></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('p29code23'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2923"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p29code23"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; example: (until (= x 10) (print x) (incf x))</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> until <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&amp;</span>body body<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;">,</span><span style="color: #b1b100;">cond</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span> <span style="color: #66cc66;">,</span>@body
	   <span style="color: #66cc66;">&#40;</span>until <span style="color: #66cc66;">,</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">,</span>@body<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><strong>for macro</strong></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('p29code24'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2924"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p29code24"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; example:</span>
<span style="color: #808080; font-style: italic;">;; (for ((i 0) (&lt; i 10) (incf i))</span>
<span style="color: #808080; font-style: italic;">;;      (print i))</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> for <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>var init-<span style="color: #b1b100;">value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">cond</span> step-block<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>body body<span style="color: #66cc66;">&#41;</span>
  `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>var <span style="color: #66cc66;">,</span>init-<span style="color: #b1b100;">value</span> <span style="color: #66cc66;">,</span>step-block<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">,</span><span style="color: #b1b100;">cond</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">,</span>@body<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>I started this yesterday and I&#8217;ll try to come up with some more. Lets see what else i can come up with <img src='http://www.adztec-independent.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
Not that this is particularly useful or anything since you really don&#8217;t <em>need</em> them, but it&#8217;s still a nice way to learn the language and especially how macros work. I&#8217;ll just keep it as a little exercise to myself in order to get to know common lisp in greater detail. <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/11/creating-standard-control-structures-in-common-lisp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My new blog&#8230;</title>
		<link>http://www.adztec-independent.de/2008/11/my-new-blog/</link>
		<comments>http://www.adztec-independent.de/2008/11/my-new-blog/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 10:20:38 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[hobbies]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[rswing]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adztec-independent.de/?p=6</guid>
		<description><![CDATA[Well, here I go again.
I guess this is my third attempt to start a webblog. Oh well.
I hope to actually make posts at a decent rate this time, since that was my main problem the last two times i started a weblog.
So, what has changed? What is this blog about? Why am I doing this?
First [...]]]></description>
			<content:encoded><![CDATA[<p>Well, here I go again.</p>
<p>I guess this is my third attempt to start a webblog. Oh well.</p>
<p>I hope to actually make posts at a decent rate this time, since that was my main problem the last two times i started a weblog.</p>
<p>So, what has changed? What is this blog about? Why am I doing this?</p>
<p>First of all, there&#8217;s lots of interesting new stuff going on in my life. Since this blog should obviously reflect my personal interests and stories, it will mainly be about what I like to do best: programming and software / computers in general.</p>
<p>I have been programming in Ruby for quite a while now &#8211; mainly webprogramming but theres also a little side project called &#8220;RSwing&#8221; which basically is a Jruby wrapper of the Java Swing GUI-Framework. And more recently I have started to learn Common Lisp which I also find very exciting and have lots of stuff to post about here.</p>
<p>So hopefully, if I manage to actually pull this through, there will be some updates on my current software projects and other stuff related to computers and my hobbies.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adztec-independent.de/2008/11/my-new-blog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
