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

<channel>
	<title>Jorge Tavares weblog &#187; Common Lisp</title>
	<atom:link href="http://jorgetavares.com/tag/common-lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://jorgetavares.com</link>
	<description></description>
	<lastBuildDate>Sun, 20 May 2012 16:27:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jorgetavares.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/dd7ededad4bb476ae4089ad9d3094443?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Jorge Tavares weblog &#187; Common Lisp</title>
		<link>http://jorgetavares.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jorgetavares.com/osd.xml" title="Jorge Tavares weblog" />
	<atom:link rel='hub' href='http://jorgetavares.com/?pushpress=hub'/>
		<item>
		<title>zsort: portable sorting algorithms in Common Lisp</title>
		<link>http://jorgetavares.com/2012/04/22/zsort-portable-sorting-algorithms-in-common-lisp/</link>
		<comments>http://jorgetavares.com/2012/04/22/zsort-portable-sorting-algorithms-in-common-lisp/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 20:15:40 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Common Lisp]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Sorting Algorithms]]></category>
		<category><![CDATA[zsort]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=1225</guid>
		<description><![CDATA[zsort is a library that I started working on as a simple hobby project. More or less around the same time I decided to check which algorithms the different Common Lisp implementations use. It is now part of Quicklisp so it can be easily used (thanks Zack!). The main goal of zsort is to be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1225&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://jorgetavares.github.com/zsort/">zsort</a> is a library that I started working on as a simple hobby project. More or less around the same time I decided to check <a href="http://jorgetavares.com/2012/02/02/sorting-algorithms-used-in-the-cl-implementations/">which algorithms the different Common Lisp implementations use</a>. It is now part of <a href="http://www.quicklisp.org/">Quicklisp</a> so it can be easily used (thanks <a href="http://xach.livejournal.com/">Zack</a>!). </p>
<p>The main goal of <a href="http://jorgetavares.github.com/zsort/">zsort</a> is to be a collection of portable sorting algorithms. If they can be fast, even better. Common lisp provides the <a href="http://www.lispworks.com/documentation/lw50/CLHS/Body/f_sort_.htm">sort</a> and <a href="http://www.lispworks.com/documentation/lw50/CLHS/Body/f_sort_.htm">stable-sort</a> functions but these can have different algorithms implemented according to each implementation, which can make an application unportable if you rely on a specific type of sorting. Also, the standard functions might not be the best for a certain situation and as such you might need a specialized sort. Even if for most situations the standard functions are more than enough, the <a href="http://jorgetavares.github.com/zsort/">zsort</a> library could be a useful complement.</p>
<p>Right now the implemented algorithms are: <a href="http://en.wikipedia.org/wiki/Insertion_sort">insertion sort</a>, <a href="http://en.wikipedia.org/wiki/Quicksort">quicksort</a>, <a href="http://en.wikipedia.org/wiki/Quicksort#Randomized_quicksort_expected_complexity">randomized quicksort</a>, <a href="http://en.wikipedia.org/wiki/Merge_sort">merge sort</a>, <a href="http://en.wikipedia.org/wiki/Heapsort">heapsort</a> and <a href="http://en.wikipedia.org/wiki/Counting_sort">counting sort</a>. The plan is to add more algorithms, for example, <a href="http://en.wikipedia.org/wiki/Bucket_sort">bucket sort</a> and <a href="http://en.wikipedia.org/wiki/Timsort">timsort</a>. However, the main thing on the todo list is adding the possibility of <a href="http://en.wikipedia.org/wiki/External_sorting">external sorting</a> (to handle large amounts of data) and parallel versions of some sorting algorithms. I am considering using <a href="http://lparallel.com/">lparallel</a> for this but I am still undecided.</p>
<p>There is still a lot of work to be done, but I think the library as it is can already be a little useful. And of course, all kind of suggestions and improvements are welcome!</p>
<br />Filed under: <a href='http://jorgetavares.com/category/programming/'>Programming</a> Tagged: <a href='http://jorgetavares.com/tag/common-lisp/'>Common Lisp</a>, <a href='http://jorgetavares.com/tag/library/'>library</a>, <a href='http://jorgetavares.com/tag/lisp/'>Lisp</a>, <a href='http://jorgetavares.com/tag/sorting-algorithms/'>Sorting Algorithms</a>, <a href='http://jorgetavares.com/tag/zsort/'>zsort</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/1225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1225&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2012/04/22/zsort-portable-sorting-algorithms-in-common-lisp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/378de7e75b3ac59ec9cab927683c0904?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">jast</media:title>
		</media:content>
	</item>
		<item>
		<title>Macros Design Patterns</title>
		<link>http://jorgetavares.com/2012/02/13/macros-design-patterns/</link>
		<comments>http://jorgetavares.com/2012/02/13/macros-design-patterns/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 11:20:25 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Common Lisp]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Macros]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=956</guid>
		<description><![CDATA[I was reading the thread What are some fun or useful macros? on reddit and it reminded me of another thread that appeared in the Pro mailing list. These kind of threads are always enjoyable because each time you learn something new and see really interesting things. While reading them, it crossed my mind that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=956&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was reading the thread <a href="http://www.reddit.com/r/lisp/comments/pg2yx/what_are_some_fun_or_useful_macros/">What are some fun or useful macros?</a> on reddit and it reminded me of <a href="http://lists.common-lisp.net/pipermail/pro/2010-September/000006.html">another thread</a> that appeared in the Pro mailing list. These kind of threads are always enjoyable because each time you learn something new and see really interesting things. While reading them, it crossed my mind that another variant of this question would be <em>what are some fun or useful macros design patterns</em>. Instead of examples of specific code macros (general or not) it would be nice to see common programming practices using macros. So, for a lack of a better expression name, let&#8217;s call them <em>macros design patterns</em>. </p>
<p>My favorite one is to configure an algorithm, especially when we want to use the correct types. Essentially, we write an algorithm using a macro that takes types or configuration arguments and then we expand it to the appropriate desired configurations. For example, if you have an algorithm that operates on different types of sequences, instead of writing several duplicate functions with the same algorithm but with the associated type declarations, just apply this pattern. A simple but contrived example: we want to compute the mean of a vector but use its proper type. In addition, we might also want the possibility of using a key to access the vector elements. We can write the following macro:</p>
<pre><code class="commonlisp">(defmacro mean-body (vector vector-type vector-ref key)
  (let ((size (gensym)) (i (gensym)))
    `(locally 
	 (declare (type ,vector-type ,vector))
       (let ((,size (length ,vector)))
	 (/ (loop for ,i from 0 below ,size
		  sum ,(if key 
			   `(funcall ,key (,vector-ref ,vector ,i))
			   `(,vector-ref ,vector ,i)))
	    ,size)))))
</pre>
<p></code></p>
<p>The macro contains the algorithm (in this simple case the mean) and the arguments allow us to configure the multiple versions we need. If we want a simple-vector, the macro will expand to use the correct type declaration and svref. If a key function is needed it will also include it. Then, we can call the macro with the several configurations value inside the main function:</p>
<pre><code class="commonlisp">(defun mean (vector &amp;optional key)
  (typecase vector
    (simple-vector 
     (if key 
	 (mean-body vector simple-vector svref key)
	 (mean-body vector simple-vector svref nil)))
    (vector 
     (if key 
	 (mean-body vector vector aref key)
	 (mean-body vector vector aref nil)))
    (otherwise 
      (if key 
	 (mean-body vector sequence elt key)
	 (mean-body vector sequence elt nil)))))
</pre>
<p></code></p>
<p>This can be very useful in situations where we want to optimize code since it becomes easy to add the proper type declarations to the input arguments of an algorithm. Moreover, we keep the algorithm in a single place, making it easier to maintain. Depending on the situation, we can also define a function for each configuration. In the example we could have a mean-simple-vector and mean-vector.</p>
<p>I don't know if it has already a specific name but I like to call it <em>the configurable algorithm pattern</em>. I find it very useful. And thinking back to the reddit <a href="http://www.reddit.com/r/lisp/comments/pg2yx/what_are_some_fun_or_useful_macros/">thread</a>, what are your favorite macros design patterns? Which ones do you find useful and use them regularly? If you want to share, feel free to drop a line. I am interested in seing and learning other patterns!  </p>
<br />Filed under: <a href='http://jorgetavares.com/category/programming/'>Programming</a> Tagged: <a href='http://jorgetavares.com/tag/common-lisp/'>Common Lisp</a>, <a href='http://jorgetavares.com/tag/design-patterns/'>Design Patterns</a>, <a href='http://jorgetavares.com/tag/lisp/'>Lisp</a>, <a href='http://jorgetavares.com/tag/macros/'>Macros</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/956/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/956/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/956/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=956&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2012/02/13/macros-design-patterns/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/378de7e75b3ac59ec9cab927683c0904?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">jast</media:title>
		</media:content>
	</item>
		<item>
		<title>Sorting algorithms used in the CL implementations</title>
		<link>http://jorgetavares.com/2012/02/02/sorting-algorithms-used-in-the-cl-implementations/</link>
		<comments>http://jorgetavares.com/2012/02/02/sorting-algorithms-used-in-the-cl-implementations/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 09:45:29 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Common Lisp]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Sorting Algorithms]]></category>
		<category><![CDATA[Survey]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=823</guid>
		<description><![CDATA[Which sorting algorithm should one implement when developing a program? The best answer is probably none. Use the sort provided by your system/library/etc. Unless you know your input data has some special properties that you can take advantage of, the provided sort should be enough for your needs and probably is more efficiently implemented. However, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=823&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Which <a href="http://en.wikipedia.org/wiki/Sorting_algorithm">sorting algorithm</a> should one implement when developing a program? The best answer is probably <em>none</em>. Use the sort provided by your system/library/etc. Unless you know your input data has some special properties that you can take advantage of, the provided sort should be enough for your needs and probably is more efficiently implemented. </p>
<p>However, I think it is important to know what sorting algorithm is implemented. If one knows the properties of the data, it is possible to understand if the provided sort can or will pose a problem. In the same way a programmer shouldn&#8217;t implement a sorting algorithm every time it needs to sort something, the programmer should also be aware of the limitations/advantages of the system sort. That way one can decide if a special sort is needed or not.</p>
<p>Common Lisp provides the functions <a href="http://www.lispworks.com/documentation/lw50/CLHS/Body/f_sort_.htm">sort</a> and <a href="http://www.lispworks.com/documentation/lw50/CLHS/Body/f_sort_.htm">stable-sort</a>. The <a href="http://www.lispworks.com/documentation/lw50/CLHS/Front/index.htm">HyperSpec</a> describes their operation well but it does not define the sorting algorithm. That decision is left free to the implementations. In addition, both functions don&#8217;t necessarily share the same algorithm. The difference between the two is that the second function sorts in a way that guarantees <a href="http://en.wikipedia.org/wiki/Sorting_algorithm#Stability">stability</a>, i.e., two elements that are equal remain in the same position after sorting is completed. The use of sort and stable-sort requires some care (see the section <a href="http://www.aiai.ed.ac.uk/~jeff/lisp/cl-pitfalls">sort pitfalls</a>) but lets focus on the algorithms and not on its usage.</p>
<p>What sorting algorithms do the major open source <a href="http://common-lisp.net/~dlw/LispSurvey.html">CL implementations</a> actually implement? I was curious about it and went to check the source for <a href="http://common-lisp.net/project/armedbear/">ABCL</a>, <a href="http://ccl.clozure.com/">CCL</a>, <a href="http://clisp.org/">CLISP</a>, <a href="http://www.cons.org/cmucl/">CMUCL</a>, <a href="http://ecls.sourceforge.net/">ECL</a> and <a href="http://www.sbcl.org/">SBCL</a>. Not surprising, we find some differences between the implementations. What it was more unexpected to discover is that some implementations also use different sorting algorithms according to the sequence type. A quick survey of the findings is summarized in the following table (if anythings is incorrect, please tell me). The links for the source code are in the implementation name (careful, in CCL and SBCL there are two links).</p>
<table style="text-align:center;" width="690" border="1">
<tbody>
<tr>
<th>Implementation</th>
<th>sort</th>
<th>stable-sort</th>
</tr>
<tr>
<td><a href="http://svn.common-lisp.net/armedbear/trunk/abcl/src/org/armedbear/lisp/sort.lisp">ABCL</a></td>
<td>merge sort (lists) / quicksort</td>
<td>merge sort</td>
</tr>
<tr>
<td><a href="http://trac.clozure.com/ccl/browser/trunk/source/level-1/l1-Mergesort.lisp">C</a><a href="http://trac.clozure.com/ccl/browser/trunk/source/lib/sort.lisp">CL</a></td>
<td>merge sort (lists) / quicksort</td>
<td>merge sort</td>
</tr>
<tr>
<td><a href="http://clisp.hg.sourceforge.net/hgweb/clisp/clisp/file/e789e5f15ae3/src/sort.d">CLISP</a></td>
<td>tree sort</td>
<td>tree sort</td>
</tr>
<tr>
<td><a href="http://trac.common-lisp.net/cmucl/browser/src/code/sort.lisp">CMUCL</a></td>
<td>heapsort</td>
<td>merge sort</td>
</tr>
<tr>
<td><a href="http://ecls.git.sourceforge.net/git/gitweb.cgi?p=ecls/ecl;a=blob;f=src/lsp/seqlib.lsp;h=4ad06d67fab06bb2263cc5b2ce54b8c0d6af09a6;hb=HEAD">ECL</a></td>
<td>merge sort (lists) / quicksort</td>
<td>quicksort (strings + bit vectors) / merge sort</td>
</tr>
<tr>
<td><a href="http://sbcl.git.sourceforge.net/git/gitweb.cgi?p=sbcl/sbcl.git;a=blob;f=src/code/sort.lisp;h=06cd2c6664d62c83d2ed7e2c28ae04b6b6478305;hb=refs/heads/master">SB</a><a href="http://sbcl.git.sourceforge.net/git/gitweb.cgi?p=sbcl/sbcl.git;a=blob;f=src/compiler/srctran.lisp;h=16accff9e535c3f8e03fccaf71884d8e1c3d8ae6;hb=refs/heads/master">CL</a></td>
<td>merge sort (lists) / heapsort</td>
<td>merge sort</td>
</tr>
</tbody>
</table>
<p>&nbsp;<br />
In terms of the implementation of sort, <a href="http://en.wikipedia.org/wiki/Quicksort">quicksort</a> is the most used algorithm, followed by <a href="http://en.wikipedia.org/wiki/Heapsort">heapsort</a>. The choice for these algorithms is expected. Both have an average-case performance of O(<em>n</em>lg<em>n</em>) and heapsort guarantees a worst-case performace of O(<em>n</em>lg<em>n</em>) too. Quicksort has a worst-case performance of O(<em>n<sup>2</sup></em>) but it can be optimized in several ways so that it also gives an expected worst-case performance of O(<em>n</em>lg<em>n</em>). However, it seems that the quicksort implementations are not completely optimized. In ECL (and ABCL) quicksort implements a partition scheme which deals better with duplicate elements (although is not the three-way partitioning) but it always picks as pivot the first element. CCL chooses the pivot with a median-of-3 method and always sorts the smaller partition to ensure a worst-case stack depth of O(lg<em>n</em>). </p>
<p>As for CLISP, I think it uses a <a href="http://en.wikipedia.org/wiki/Tree_sort">tree sort</a> but I am not entirely sure. The only source file I could find with a sort implementation was <a href="http://clisp.hg.sourceforge.net/hgweb/clisp/clisp/file/e789e5f15ae3/src/sort.d">sort.d</a> and it looks like it contains an implementation of tree sort with a self-balanced binary tree, which also gives this algorithm an average and worst-case performance of O(<em>n</em>lg<em>n</em>). </p>
<p>As expected, most of the implementations use <a href="http://en.wikipedia.org/wiki/Merge_sort">merge sort</a> to implement stable-sort since it is a stable sort with average and worst-case performance of O(<em>n</em>lg<em>n</em>). Apparently, all implementations are bottom-up merge sorts with the exception of CCL and ECL. Another interesting thing is that merge sort is also used for lists in sort, in most of the implementations. However, I found it surprising to find quicksort in the stable-sort column because it is not a stable algorithm. Since it is only used for strings and bit vectors, it is not really an issue. While reading the source code of the implementations, I realized that ABCL was using quicksort in stable-sort for all non-list sequences. This is a problem that exists in the current <a href="http://common-lisp.net/project/armedbear/releases/1.0.1/">1.0.1 release</a> but I&#8217;ve sent a <a href="http://trac.common-lisp.net/armedbear/ticket/196">bug report</a> <a href="http://trac.common-lisp.net/armedbear/changeset/13838">with a quick fix</a> to the maintainers. The next release should have stable-sort fixed.</p>
<p>This exploration of the sorting algorithms used in the open source implementations was very educational and interesting to me. I&#8217;ve learned what algorithms are actually used and enjoyed seing how they were implemented. Just spotting the issue in ABCL stable-sort made this review worthwhile. I think there is still room for improvement in some implementations but knowing now the strengths and weaknesses of the sorts in CL is already good enough. On a final note, I just wonder what are the algorithms used in <a href="http://www.franz.com/products/allegro-common-lisp/">ACL</a> and <a href="http://www.lispworks.com/products/lispworks.html">LW</a>.   </p>
<br />Filed under: <a href='http://jorgetavares.com/category/programming/'>Programming</a> Tagged: <a href='http://jorgetavares.com/tag/common-lisp/'>Common Lisp</a>, <a href='http://jorgetavares.com/tag/lisp/'>Lisp</a>, <a href='http://jorgetavares.com/tag/sorting-algorithms/'>Sorting Algorithms</a>, <a href='http://jorgetavares.com/tag/survey/'>Survey</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/823/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=823&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2012/02/02/sorting-algorithms-used-in-the-cl-implementations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/378de7e75b3ac59ec9cab927683c0904?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">jast</media:title>
		</media:content>
	</item>
		<item>
		<title>Packages organization and exporting symbols</title>
		<link>http://jorgetavares.com/2011/11/08/packages-organization-and-exporting-symbols/</link>
		<comments>http://jorgetavares.com/2011/11/08/packages-organization-and-exporting-symbols/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 16:43:04 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Common Lisp]]></category>
		<category><![CDATA[HyperSpec]]></category>
		<category><![CDATA[Packages]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=792</guid>
		<description><![CDATA[I&#8217;ve started to re-design my main library for evolutionary computation. One of the main things I did for the new version was a complete new organization of the packages (and respective files/modules). Before I had essentially two main packages, the library itself and the examples. Although simple, it became a pain to use this model [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=792&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started to re-design my main library for evolutionary computation. One of the main things I did for the new version was a complete new organization of the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/11_aa.htm">packages</a> (and respective files/modules). Before I had essentially two main packages, the library itself and the examples. Although simple, it became a pain to use this model when I extended it heavily with more algorithms and related utilities. I hope I am not going now in the opposite direction (too complicated) but so far I like the new organization. </p>
<p>In short, there is a package for each main branch of algorithms (e.g., GA, GP) with everything specific that   kind, which imports from a core package with the common components. These &#8220;sub-packages&#8221; are gathered together in a single package (the main library package). This way, it is possible to use in a project everything or simply just the desired component (e.g., if you just want GP). Furthermore, an extra package for the users is also provided to allow <a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a> experimentation without being on the library main package. </p>
<p>However, while implementing this scheme I realized that I wanted to have all the exported symbols from the packages that compose the library, also exported by the library main package. This way, all the symbols that compose the library are easily seen on the main package. For me this is very useful since it allows exploration of a library, especially if it has many things. Since I have never done something like this before, I went and search for a way to solve this minor problem in an easy way. </p>
<p>The answer is basically use <strong><a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_do_sym.htm">do-external-symbols</a></strong>. With this macro you iterate over the exported symbols of a given package and then <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_export.htm">export</a> them again on the package you want. Do this inside an <a href="http://www.lispworks.com/documentation/HyperSpec/Body/s_eval_w.htm">eval-when</a> form and when the library is loaded and the main package will contain all the symbols. If *library-sub-packages* is a list with the packages labels that compose your library:</p>
<p><code>
<pre>
(eval-when (:compile-toplevel :compile-toplevel :execute)
  (dolist (package *library-sub-packages*)
    (do-external-symbols (symbol (find-package package))
      (export symbol (find-package *library-main-package*)))))
</pre>
<p></code></p>
<p>Making all the exported symbols of internal packages also exportable by the main package turn out to be an easy thing to do. I don&#8217;t recall seing do-external-symbols (or the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_do_sym.htm">related macros</a>) but I&#8217;m glad such a macro is provided. As always, the <a href="http://www.lispworks.com/documentation/HyperSpec/Front/index.htm">HyperSpec</a> is your friend :-)</p>
<br />Filed under: <a href='http://jorgetavares.com/category/programming/'>Programming</a> Tagged: <a href='http://jorgetavares.com/tag/common-lisp/'>Common Lisp</a>, <a href='http://jorgetavares.com/tag/hyperspec/'>HyperSpec</a>, <a href='http://jorgetavares.com/tag/packages/'>Packages</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/792/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/792/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/792/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/792/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/792/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/792/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/792/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/792/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=792&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2011/11/08/packages-organization-and-exporting-symbols/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/378de7e75b3ac59ec9cab927683c0904?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">jast</media:title>
		</media:content>
	</item>
		<item>
		<title>ECLM 2011 Notes</title>
		<link>http://jorgetavares.com/2011/10/26/eclm-2011-notes/</link>
		<comments>http://jorgetavares.com/2011/10/26/eclm-2011-notes/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 21:19:47 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Common Lisp]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Meetings]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=751</guid>
		<description><![CDATA[This last weekend I was in Amsterdam to attend the European Common Lisp Meeting. This was my third participation in a organized Lisp meeting (after the first ZSLUG in Zurich and the ELS 2011 in Hamburg) and I am happy I&#8217;ve decided to go. I was only present at the meeting itself since going to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=751&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This last weekend I was in <a href="http://en.wikipedia.org/wiki/Amsterdam">Amsterdam</a> to attend the <a href="http://weitz.de/eclm2011/">European Common Lisp Meeting</a>. This was my third participation in a organized Lisp meeting (after the <a href="http://zslug.wordpress.com/2011/02/09/meeting-1-report-audio-und-slideware-of-hans-talk/">first ZSLUG</a> in Zurich and the <a href="http://www.european-lisp-symposium.org/">ELS 2011</a> in Hamburg) and I am happy I&#8217;ve decided to go. I was only present at the meeting itself since going to the dinners and city tour would have been way out of my budget. Anyway, the ECLM was a nice venue. I enjoyed most of the talks and still had an opportunity to talk with fellow lispers. I enjoyed talking with <a href="http://kvardek-du.kerno.org/">Luís Oliveira</a> and meeting <a href="http://www.xach.com/">Zach Beane</a>.</p>
<p>The <a href="http://lisp-book.org/talks/eclm-2011-10-23/html/00-title.html">first talk</a> was given by <a href="http://www.nicklevine.org/">Nick Levine</a> and it can be viewed in two parts. In the first one, he talked about his experiences of trying to write a <a href="http://lisp-book.org/">CL book</a> for <a href="http://oreilly.com/">O&#8217;Reilly</a>. It was quite interesting to see how hard can it be to prepare a book, especially for a publisher who was (is?) <a href="http://lisp-book.org/talks/eclm-2011-10-23/html/03-not-looking.html">not very lisp-friendly</a>. The second part was mostly about the community, although presented with a rant on libraries. This is a topic that has been debated several times. Thanks to <a href="http://www.quicklisp.org/">Quicklisp</a>, the problem now is not installing libraries but <em>finding them and knowing which ones are good</em>. I am not sure if creating another site as suggested would be a good thing since resources are already scarce. Perhaps more thought must be made in how to improve the current ones. <a href="http://www.cliki.net/index">CLiki</a> still seems to me the best starting point. Still, Nick Levine talk was good and entertaining. One of the best in the meeting.</p>
<p>The following talks were mostly about companies that use CL as their main programming language. <a href="http://www.frobenius.com/">Jack Harper</a> talked about the company he recently started, <a href="http://www.secureoutcomes.net/">Secure Outcomes</a>, that produces a unique <a href="http://www.secureoutcomes.net/livescan-products.html">portable fingerprint scanner</a>. I must say his talk was quite inspiring! He talked about how to get a startup running and the decisions that took him to choose Lisp as the main development language. In addition, he also explained why prefers Lispworks to any other implementation. </p>
<p>Next, it was the talk given by Dave Cooper. I must confess his talk was the weaker of the day mainly because he talked about two different subjects without any connection. He started talking about <a href="http://genworks.com/downloads/customer-documentation/index.xml">GDL</a>, the main product from his company, <a href="http://genworks.com/">Genworks</a>. I&#8217;m sure GDL can be a great thing but I didn&#8217;t get much from his talk. About halftime, the talk suddenly changed to the <a href="http://www.cl-foundation.org/">Common Lisp Foundation</a>. This was the interesting part of the talk since he explained the aims of CLF, the people behind it, etc. However, it was not clear how it will distinguish itself from ALU in terms of operation (in terms of purpose, CLF just focus on Common Lisp while ALU in all Lisp dialects) and this was the main concern that was expressed during the questions time. After presenting CLF, and since there was still some time left for the next presenter, he went back to GDL.</p>
<p>Afterwards, it was the turn of <a href="http://lukego.livejournal.com/">Luke Gorrie</a> to present his lisp-hacker startup <a href="http://teclo.net/">Teclo Networks</a>. His talk was an expanded/updated version of the one given in Zurich. Still, it was also quite interesting. He started by telling how a group of hackers with a Lisp and/or <a href="http://www.erlang.org/">Erlang</a> background got together to improve the mobile TCP/IP communications. Then, he showed us how TCP badly misbehaves in a mobile network and how their product, <a href="http://teclo.net/products/sambal/">Sambal</a>, can give 10% to 27% improvements. Another interesting point of the talk was that CL is used as their main development language. In short, it is used to develop and study all their algorithms. They have a TCP/IP stack fully implemented in CL! Moreover, all their analysis and maintenance tools are also all in CL. However, in the actual product boxes they have reimplemented the algorithms in C. The reason: extreme pragmatism. Luke concluded by hinting that the sales of their product is going very well! </p>
<p>In the afternoon the talks started with Paul Miller from <a href="http://www.xanalys.com/">Xanalys</a>. The talk was dedicated to <a href="http://www.xanalys.com/solutions/linkexplorer.html">Link Explorer</a>, a windows desktop tool to analyze data. The application is quite impressive and was developed using just CL. Paul also gave us a demonstration of the tool as well as some notes on future development. </p>
<p>The best and most awaited talk, <em>Quicklisp, technically and socially</em>, was given by <a href="http://www.xach.com/">Zach Beane</a>. The talk focused on several aspects of <a href="http://www.quicklisp.org/">Quicklisp</a>. Zach started by giving an overview of the famous library problem of CL, the solutions that existed before QL, explaining their advantages and disadvantages. Also, and very important, what people were actually using and what difficulties they were facing. In a survey he did, most CL programmers were installing libraries by hand, including Zach! Then he proceed to how Quicklisp was developed, some technical issues, what is the role of Quicklisp and what is the reception after one year. The talk focused then on the social impact of Quicklisp in the community. One of the things that makes Zach happy it&#8217;s the number of emails he gets saying that people are back to using CL and contributing more to the community (i.e., making libraries available) because of QL. Finally, some indications of what is to come. My perception is that the possibility to enable hacking as it was possible with clbuild is one of the most exciting future features for Quicklisp. Zach&#8217;s talk was excellent from all points of view!</p>
<p>The last talk of the day was by <a href="http://netzhansa.blogspot.com/">Hans Hübner</a>. This was my second favorite presentation. Although the topic, code style and conventions, can start some heated discussions, I must say that I agree with almost everything Hans Hübner mentioned. However, like everything, some common sense is always necessary. One of the main points was that lispers should not use constructions which are not part of the standard language when the standard provide options, just because you want to save some typing. It is more important for another programmer to understand faster what is written than forcing him to look for the definition of the unusual constructs. The <a href="http://double.co.nz/cl/ifstar.lisp">if*</a>, bind were examples given. Hans also talked abut the 80-column rule, style guides, etc. In the end, it always depends on the project, the people, etc, but code style is important and should not be ignored.</p>
<p>The meeting ended with several lightning talks. The most interesting bits were: <a href="http://within-parens.blogspot.com/">Marco Antoniotti</a> announced <a href="http://ozk.unizd.hr/els2012/">ELS 2012</a>, to be held in Zadar, Croatia, around April-May; <a href="http://www.doc.gold.ac.uk/~mas01cr/">Christophe Rhodes</a> talked again about <a href="http://common-lisp.net/~crhodes/swankr/">swankr</a>, a swank and <a href="http://common-lisp.net/project/slime/">slime</a> for <a href="http://www.r-project.org/">R</a>; the <a href="http://abcl-dev.blogspot.com/2011/10/abcl-100-released.html">announcement</a> of <a href="http://common-lisp.net/project/armedbear/">ABCL</a> 1.0.0 by Erik Huelsmann. </p>
<p>Some words on the organization. Organizing a meeting of this kind is not easy and <a href="http://weitz.de/">Edi Weitz</a> and Arthur Lemmens must be congratulated for making a great event. Not all was perfect but everything went smoothly. I wish that it continues to happen in the coming years! </p>
<br />Filed under: <a href='http://jorgetavares.com/category/programming/'>Programming</a> Tagged: <a href='http://jorgetavares.com/tag/common-lisp/'>Common Lisp</a>, <a href='http://jorgetavares.com/tag/lisp/'>Lisp</a>, <a href='http://jorgetavares.com/tag/meetings/'>Meetings</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/751/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=751&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2011/10/26/eclm-2011-notes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/378de7e75b3ac59ec9cab927683c0904?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">jast</media:title>
		</media:content>
	</item>
	</channel>
</rss>
