{"id":126,"date":"2007-10-24T00:17:02","date_gmt":"2007-10-23T23:17:02","guid":{"rendered":"http:\/\/people.iola.dk\/arj\/2007\/10\/24\/the-power-of-lisp-part-1\/"},"modified":"2008-03-05T02:14:54","modified_gmt":"2008-03-05T01:14:54","slug":"the-power-of-lisp-part-1","status":"publish","type":"post","link":"https:\/\/people.iola.dk\/arj\/2007\/10\/24\/the-power-of-lisp-part-1\/","title":{"rendered":"The power of lisp part 1"},"content":{"rendered":"<p>Lately I&#8217;ve been reading the book <a href=\"http:\/\/www.gigamonkeys.com\/book\/\">Practical Common Lisp<\/a>. My earlier experience with lisp was at the university where I briefly touched lisp in the form of the Scheme dialect. After having read Paul Grahams excellent <a href=\"http:\/\/www.oreilly.com\/catalog\/hackpaint\/\">Hackers and Painters<\/a> twice, I thought it would probably be a good idea to see if lisp lived up to the hype. After seeing Practical Common Lisp being recommended by <a href=\"http:\/\/blogs.codehaus.org\/people\/bamboo\/\">bamboo<\/a> of <a href=\"http:\/\/boo.codehaus.org\">boo<\/a> fame and seeing this <a href=\"http:\/\/video.google.com\/videoplay?docid=448441135356213813\">google tech talk<\/a> I was convinced that the book was the best way to see all the wonderful stuff lisp has to offer.<\/p>\n<p>So far I&#8217;ve been quite impressed with some of the things one can do in the language in a very elegant way. And I suddenly understand why closures work the way it does in C# and python. The problem with moving stuff from a really dynamic language like lisp to a static language like C# is that not everything fits just as fine and you&#8217;ll find yourself wondering why the hell code like <a href=\"http:\/\/people.iola.dk\/anders\/example.cs\">this<\/a> returns 10 times 9 instead of 0 to 9. Another thing is that I often find myself remembering small code idioms that just completely goes away when one can build abstractions so easily. The first example is if you want to break out of a double loop. A situation more often that one would think.<\/p>\n<p>I C# one could write a double loop something like <a href=\"http:\/\/people.iola.dk\/anders\/example2.cs\">this<\/a>. Notice the introduction of the found variable which is needed to make sure that the loop doesn&#8217;t do needless work. Even with an anonymous function it&#8217;s quite ugly (and the same is true for a goto solution :)). In lisp it would look something like <a href=\"http:\/\/people.iola.dk\/anders\/example2.lisp\">this<\/a> (my first common lisp program :-)). The abstraction is in the <strong>block<\/strong> concept and in the generalized return construct <strong>return-from<\/strong>.<\/p>\n<p>Edit: Can be simplyfied to this:<\/p>\n<pre class=\"prettyprint\">\r\n(let ((l (list (list 1 2 3 4) (list 5 6 7))))\r\n  (loop named outer for i in l do\r\n\t(loop for j in i do\r\n\t      (when (= j 3)\r\n\t\t(format t \"found value, yeah!\")\r\n\t\t(return-from outer)))))<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Lately I&#8217;ve been reading the book Practical Common Lisp. My earlier experience with lisp was at the university where I briefly touched lisp in the form of the Scheme dialect. After having read Paul Grahams excellent Hackers and Painters twice, I thought it would probably be a good idea to see if lisp lived up [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,12,19],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-boo","category-books","category-programming"],"_links":{"self":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":0,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"wp:attachment":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}