<?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</title>
	<atom:link href="http://jorgetavares.com/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</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>Professional Change</title>
		<link>http://jorgetavares.com/2012/05/20/professional-change/</link>
		<comments>http://jorgetavares.com/2012/05/20/professional-change/#comments</comments>
		<pubDate>Sun, 20 May 2012 16:21:31 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Self]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=1251</guid>
		<description><![CDATA[After many years in academia doing research, I&#8217;ve recently joined the software industry. I am now working at Microsoft, specifically, at their Search Technology Center in Munich. It&#8217;s an exciting and challenging work! I will continue doing my Common Lisp explorations in my free time and talk about them in here as before (disclaimer: the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1251&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After many years in academia <a href="http://jorgetavares.com/publications/">doing research</a>, I&#8217;ve recently joined the software industry. I am now working at <a href="http://www.microsoft.com">Microsoft</a>, specifically, at their <a href="http://www.microsoft.com/en-us/mtc/locations/munich.aspx">Search Technology Center in Munich</a>. It&#8217;s an exciting and challenging work! </p>
<p>I will continue doing my <a href="http://en.wikipedia.org/wiki/Common_Lisp">Common Lisp</a> explorations in my free time and talk about them in here as before (disclaimer: the views and opinions expressed on this blog are my own and not those of my employer).</p>
<br />Filed under: <a href='http://jorgetavares.com/category/blog/'>Blog</a> Tagged: <a href='http://jorgetavares.com/tag/self/'>Self</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/1251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/1251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/1251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/1251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/1251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/1251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/1251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/1251/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1251&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2012/05/20/professional-change/feed/</wfw:commentRss>
		<slash:comments>0</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>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>Best Paper Award at EuroGP 2012</title>
		<link>http://jorgetavares.com/2012/04/17/best-paper-award-at-eurogp-2012/</link>
		<comments>http://jorgetavares.com/2012/04/17/best-paper-award-at-eurogp-2012/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 20:51:29 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Publications]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Ant System]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[EuroGP]]></category>
		<category><![CDATA[Evo*]]></category>
		<category><![CDATA[Grammatical Evolution]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=1197</guid>
		<description><![CDATA[Last week I was at EuroGP where I presented my latest paper &#8220;Automatic Design of Ant Algorithms with Grammatical Evolution&#8221; (pdf, slides) and it won the Best Paper Award! I am very happy with this distinction since EuroGP is the leading conference on Genetic Programming attended by the best researchers in the field. In this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1197&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://jorgetavares.files.wordpress.com/2012/04/evostar2012.png"><img src="http://jorgetavares.files.wordpress.com/2012/04/evostar2012.png?w=300&h=108" alt="" title="evostar2012" width="300" height="108" class="alignnone size-medium wp-image-1206" /></a></p>
<p>Last week I was at <a href="http://evostar.dei.uc.pt/2012/call-for-contributions/eurogp/">EuroGP</a> where I presented my latest paper &#8220;<a href="http://www.springerlink.com/content/n7201w979k6q8628/?MUD=MP">Automatic Design of Ant Algorithms with Grammatical Evolution</a>&#8221; (<a href="http://jorgetavares.files.wordpress.com/2008/04/2012_eurogp.pdf">pdf</a>, <a href="http://speakerdeck.com/embed/4f8db4d3cce23a002202468e?#">slides</a>) and it won the <strong>Best Paper Award</strong>! I am very happy with this distinction since EuroGP is the leading conference on Genetic Programming attended by the best researchers in the field. </p>
<p>In this paper, a <a href="http://en.wikipedia.org/wiki/Grammatical_evolution">Grammatical Evolution</a> approach is used for the automatic design of <a href="http://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms">Ant Colony Optimization</a> algorithms. The used  grammar has the ability to guide the learning of novel architectures, by rearranging components regularly found on manually designed variants (for example, the Elitist Ant-System, the Ant Colony System or the Max-Min Ant System). This approach was tested with the <a href="http://en.wikipedia.org/wiki/Travelling_salesman_problem">TSP</a> and the results show that the evolved algorithmic strategies are effective, exhibit a good generalization capability and are competitive with human designed variants. This is still a starting point and there is a large amount of work to be done but the indications given by these results are encouraging! </p>
<p>This year the conference took place in <a href="http://en.wikipedia.org/wiki/M%C3%A1laga">Málaga</a>, Spain, as part of <a href="http://evostar.org/">Evo*</a> as usual. The event was great with an excellent organization lead  by <a href="http://www.lcc.uma.es/~ccottap/">Carlos Cotta</a>. It was a fantastic Evo*! Next year it will be held in <a href="http://en.wikipedia.org/wiki/Vienna">Wien</a>!</p>
<br />Filed under: <a href='http://jorgetavares.com/category/publications/'>Publications</a>, <a href='http://jorgetavares.com/category/research/'>Research</a> Tagged: <a href='http://jorgetavares.com/tag/ant-system/'>Ant System</a>, <a href='http://jorgetavares.com/tag/conferences/'>Conferences</a>, <a href='http://jorgetavares.com/tag/eurogp/'>EuroGP</a>, <a href='http://jorgetavares.com/tag/evo/'>Evo*</a>, <a href='http://jorgetavares.com/tag/grammatical-evolution/'>Grammatical Evolution</a>, <a href='http://jorgetavares.com/tag/publications/'>Publications</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/1197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/1197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/1197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/1197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/1197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/1197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/1197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1197&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2012/04/17/best-paper-award-at-eurogp-2012/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>

		<media:content url="http://jorgetavares.files.wordpress.com/2012/04/evostar2012.png?w=300" medium="image">
			<media:title type="html">evostar2012</media:title>
		</media:content>
	</item>
		<item>
		<title>Book review: The Tangled Web</title>
		<link>http://jorgetavares.com/2012/02/16/book-review-the-tangled-web/</link>
		<comments>http://jorgetavares.com/2012/02/16/book-review-the-tangled-web/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 17:43:44 +0000</pubDate>
		<dc:creator>Jorge Tavares</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Book review]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://jorgetavares.com/?p=1097</guid>
		<description><![CDATA[For the past couple of months I&#8217;ve been reading The Tangled Web: A Guide to Securing Modern Web Applications by Michael Zalewski. The book was published by no starch press and they were kind enough to provide me a copy for review. I enjoy reading about topics outside my main field and interests. It&#8217;s a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1097&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://jorgetavares.files.wordpress.com/2012/02/tangledweb_cvr-webquality.png"><img src="http://jorgetavares.files.wordpress.com/2012/02/tangledweb_cvr-webquality.png?w=700" alt="" title="tangledWeb_cvr-webquality"   class="alignnone size-full wp-image-1102" /></a></p>
<p>For the past couple of months I&#8217;ve been reading <a href="http://lcamtuf.coredump.cx/tangled/">The Tangled Web: A Guide to Securing Modern Web Applications</a> by <a href="http://lcamtuf.coredump.cx/">Michael Zalewski</a>. The book was published by <a href="http://nostarch.com/">no starch press</a> and they were kind enough to provide me a copy for review. I enjoy reading about topics outside my main field and interests. It&#8217;s a way to keep myself informed and learn new things and this book fits exactly into this category. </p>
<p>The Tangled Web is mostly about web technologies and how insecure they are by nature. The book is a very engaging narrative, full of details and impressive war stories. It focuses on the practical issues of web technologies and not on the theory of security. The book can be very useful for web developers and those interested in security. For example, at the end of each chapter we can find a &#8220;Security Engineering Cheat Sheet&#8221;, which presents us a summary of things to consider/do. These sheets alone make the book worthwhile having. The book is organized in three main parts. In the first one, the author tells us the story of the inception of the web until today and discusses all the important technologies, protocols, etc. The second part focuses on the browser security and the third part on &#8220;the things to come&#8221;. Although the book is not very thick (around 300 pages) it addresses too many important issues to completely absorb them in a single reading. </p>
<p>To conclude, the Tangled Web is a solid book, full of interesting and useful information. For web developers and security experts it should be a must read book. For the rest of us it is an enjoyable reading. </p>
<br />Filed under: <a href='http://jorgetavares.com/category/programming/'>Programming</a> Tagged: <a href='http://jorgetavares.com/tag/book-review/'>Book review</a>, <a href='http://jorgetavares.com/tag/security/'>Security</a>, <a href='http://jorgetavares.com/tag/web/'>Web</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jorgetavares.wordpress.com/1097/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jorgetavares.wordpress.com/1097/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jorgetavares.wordpress.com/1097/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jorgetavares.wordpress.com/1097/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jorgetavares.wordpress.com/1097/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jorgetavares.wordpress.com/1097/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jorgetavares.wordpress.com/1097/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jorgetavares.wordpress.com/1097/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jorgetavares.com&#038;blog=3353190&#038;post=1097&#038;subd=jorgetavares&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jorgetavares.com/2012/02/16/book-review-the-tangled-web/feed/</wfw:commentRss>
		<slash:comments>0</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>

		<media:content url="http://jorgetavares.files.wordpress.com/2012/02/tangledweb_cvr-webquality.png" medium="image">
			<media:title type="html">tangledWeb_cvr-webquality</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>
	</channel>
</rss>
