<?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>Reality tunnels &#187; lisp</title>
	<atom:link href="http://blog.superadditive.com/tag/lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.superadditive.com</link>
	<description>A glimpse into my visual space</description>
	<lastBuildDate>Wed, 16 Dec 2009 09:56:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Trivial doctests in Common Lisp</title>
		<link>http://blog.superadditive.com/2007/12/06/trivial-doctests-in-common-lisp/</link>
		<comments>http://blog.superadditive.com/2007/12/06/trivial-doctests-in-common-lisp/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 11:50:32 +0000</pubDate>
		<dc:creator>jmbr</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://blog.superadditive.com/2007/12/06/trivial-doctests-in-common-lisp/</guid>
		<description><![CDATA[The pros and cons of doctests have been discussed elsewhere so I won&#8217;t enter that debate here. I was told it was trivial to roll your own doctest suite in Common Lisp. I have done that and it is easy indeed but I have included the code in incf-cl for those who would like to [...]]]></description>
			<content:encoded><![CDATA[<p>The pros and cons of <a href="http://en.wikipedia.org/wiki/Doctest">doctests</a> have been <a href="http://groups.google.com/group/comp.lang.lisp/search?group=comp.lang.lisp&amp;q=doctest&amp;qt_g=Search+this+group">discussed elsewhere</a> so I won&#8217;t enter that debate here.</p>
<p>I was told it was trivial to roll your own doctest suite in Common Lisp.  I have done that and it is easy indeed but I have included the code in <a href="http://superadditive.com/projects/incf-cl">incf-cl</a> for those who would like to use it right away.<br />
<span id="more-77"></span><br />
Here&#8217;s an example:</p>
<pre>  (<span style="color: #afeeee;"><strong>defpackage</strong></span> <span style="color: #87ceeb;"><strong>:test</strong></span>
    (<span style="color: #7fffd4;">:use</span> <span style="color: #7fffd4;">:common-lisp</span> <span style="color: #7fffd4;">:incf-cl</span>)
    (<span style="color: #7fffd4;">:export</span> <span style="color: #7fffd4;">:factorial</span>))

  (<span style="color: #afeeee;"><strong>in-package</strong></span> <span style="color: #7fffd4;">:test</span>)

  (<span style="color: #afeeee;"><strong>defun</strong></span> <span style="color: #7fffd4;"><strong>factorial</strong></span> (n <span style="color: #87ceeb;"><strong>&amp;optional</strong></span> (acc 1))
    <span style="color: #87cefa;">"Returns the factorial of N, where N is an integer &gt;= 0.

    Examples:

    TEST&gt; (assemble (factorial n) (&lt;- n (range 1 5)))
    (1 2 6 24 120)

    TEST&gt; (factorial 450/15)
    265252859812191058636308480000000

    TEST&gt; (signals-p arithmetic-error (factorial -1))
    T

    TEST&gt; (signals-p type-error (factorial 30.1))
    T

    TEST&gt; (factorial 0)
    1"</span>
    (<span style="color: #afeeee;"><strong>declare</strong></span> (type integer n))

    (<span style="color: #afeeee;"><strong>cond</strong></span>
      ((minusp n) (<span style="color: #ff0000;"><strong>error</strong></span> 'arithmetic-error))
      ((/= n (floor n)) (<span style="color: #ff0000;"><strong>error</strong></span> 'type-error)))

    (<span style="color: #afeeee;"><strong>if</strong></span> (= n 0)
        acc
        (factorial (1- n) (* n acc))))</pre>
<pre><span style="color: #afeeee;"><strong>CL-USER&gt; </strong></span><strong>(doctest :test)</strong>
<span style="color: #87cefa;">.....</span><span style="color: #ff0000;">T</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.superadditive.com/2007/12/06/trivial-doctests-in-common-lisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List comprehensions in Common Lisp</title>
		<link>http://blog.superadditive.com/2007/11/09/list-comprehensions-in-common-lisp/</link>
		<comments>http://blog.superadditive.com/2007/11/09/list-comprehensions-in-common-lisp/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 15:23:40 +0000</pubDate>
		<dc:creator>jmbr</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.superadditive.com/2007/11/09/list-comprehensions-in-common-lisp/</guid>
		<description><![CDATA[List comprehensions are a programming language construct that closely mimics the way you declare a set in mathematics and sometimes are more succinct and readable than using a composition of mapcar, delete-if or an ad hoc imperative loop. Having list comprehensions in Lisp was something I was missing from Python and Haskell. So I tried [...]]]></description>
			<content:encoded><![CDATA[<p>List comprehensions are a programming language construct that closely mimics the way you declare a set in mathematics and sometimes are more succinct and readable than using a composition of <strong>mapcar</strong>, <strong>delete-if</strong> or an ad hoc imperative loop.</p>
<p>Having list comprehensions in Lisp was something I was missing from Python and Haskell.  So I tried to find something similar and discovered that <span id="more-71"></span> <a href="http://subpic.blogspot.com/2007/02/more-then-list-comprehensions-lisp-loop.html">the LOOP facility can be used as a means of achieving this goal</a> but this, although nice, didn&#8217;t feel natural enough.  In the end, I read the paper <a href="http://www.iro.umontreal.ca/~latendre/publications/listCompFinal.pdf">Simple and Efficient Compilation of List Comprehension in Common Lisp</a> by Mario Latendresse which appeared at <a href="http://www.international-lisp-conference.org/2007/speakers#latendresse_mario">ILC 2007</a> and have decided to adopt that implementation for translating list comprehensions into <strong>loop</strong>s.</p>
<p>For example, the set</p>
<p><img style="border: 0;" src="http://superadditive.com/cgi/mimetex.cgi?\reverse%20\large%20\{%20(x,%20y)%20\in%20\{0,%201,%202\}^2%20|%20x%20+%20y%20=%202%20\}" alt="\{ (x, y) \in \{0, 1, 2\}^2 | x +y = 2&lt;br /&gt; \}" /></p>
<p>can be expressed as</p>
<pre><strong>(lc (cons x y) (&lt;- x '(0 1 2)) (&lt;- y '(0 1 2)) (= (+ x y) 2)) </strong> ==&gt;
<span style="color: #ff0000;">((0 . 2) (1 . 1) (2 . 0))</span></pre>
<p>Another example:</p>
<pre><strong>(lc (sin x) (&lt;- x (range 0 .1 (/ pi 2))))</strong> ==&gt;
<span style="color: #ff0000;">(0.0 0.09983342 0.19866933 0.29552022 0.38941833 0.47942555 0.5646425 0.6442177
 0.71735615 0.783327 0.8414711 0.8912074 0.93203914 0.96355826 0.9854498
 0.997495)</span></pre>
<p>The macro I&#8217;m using is <strong>lc</strong>:</p>
<pre>(<span style="color: #afeeee;"><strong>defmacro</strong></span> <span style="color: #7fffd4;"><strong>lc</strong></span> (collection-form <span style="color: #87ceeb;"><strong>&amp;rest</strong></span> quantifiers)
  <span style="color: #87cefa;">"Assembles a multiset containing the results of evaluating
COLLECTION-FORM and subject to QUANTIFIERS."</span>
  (<span style="color: #afeeee;"><strong>labels</strong></span> ((translate (collection-form qs)
             (<span style="color: #afeeee;"><strong>if</strong></span> (null qs)
                 `(collect ,collection-form)
                 (translate-generator-or-filter collection-form qs)))
           (translate-generator-or-filter (collection-form qs)
             (<span style="color: #afeeee;"><strong>let</strong></span> ((q (first qs))
                   (qr (rest qs)))
               (<span style="color: #afeeee;"><strong>if</strong></span> (eq (first q) '&lt;-)
                   (translate-generator collection-form (second q) (third q) qr)
                   (translate-filter collection-form q qr))))
           (translate-generator (collection-form variable collection qs)
             `(nconc (<span style="color: #afeeee;"><strong>loop</strong></span> for ,variable in ,collection
                          ,@(translate collection-form qs))))
           (translate-filter (collection-form filter-form qs)
             `(<span style="color: #afeeee;"><strong>when</strong></span> ,filter-form ,@(translate collection-form qs))))
    (<span style="color: #afeeee;"><strong>when</strong></span> quantifiers
      `(<span style="color: #afeeee;"><strong>loop</strong></span> repeat 1 ,@(translate collection-form quantifiers)))))</pre>
<p>and the helper function <a title="range.lisp" href="http://blog.superadditive.com/wp-content/uploads/2007/11/range.lisp"><strong>range</strong></a> is:</p>
<pre>(<span style="color: #afeeee;"><strong>defun</strong></span> <span style="color: #7fffd4;"><strong>range</strong></span> (a b <span style="color: #87ceeb;"><strong>&amp;optional</strong></span> c)
  <span style="color: #87cefa;">"Builds a range of numbers as Matlab would do"</span>
  (<span style="color: #afeeee;"><strong>flet</strong></span> ((|:| (start step stop)
           (<span style="color: #ff0000;"><strong>assert</strong></span> (and (&lt;= start stop) (&gt; step 0)))
           (<span style="color: #afeeee;"><strong>loop</strong></span> for x from start to stop by step collect x)))
    (<span style="color: #afeeee;"><strong>if</strong></span> c
        (|:| a b c)
        (|:| a 1 b))))</pre>
<p>A possible enhancement would be to translate to <strong>series</strong> instead<br />
of <strong>loop</strong> in order to have lazy list comprehensions.</p>
<p>This code (and more) can be found in the <a href="http://superadditive.com/projects/incf-cl/">(incf cl) utilities</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.superadditive.com/2007/11/09/list-comprehensions-in-common-lisp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>cl-buchberger is out!</title>
		<link>http://blog.superadditive.com/2007/10/19/cl-buchberger-is-out/</link>
		<comments>http://blog.superadditive.com/2007/10/19/cl-buchberger-is-out/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 18:36:10 +0000</pubDate>
		<dc:creator>jmbr</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.superadditive.com/2007/10/19/cl-buchberger-is-out/</guid>
		<description><![CDATA[I&#8217;ve just released the first version of cl-buchberger, a Common Lisp implementation of Buchberger&#8217;s algorithm for the computation of Gröbner bases. There are many improvements waiting in the pipeline but the basic functionality is there. You can read more about cl-buchberger here.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released the first version of cl-buchberger, a Common Lisp<br />
implementation of Buchberger&#8217;s algorithm for the computation of<br />
Gröbner bases.</p>
<p>There are many improvements waiting in the pipeline but the basic<br />
functionality is there.</p>
<p><img src="http://blog.superadditive.com/wp-content/uploads/2007/10/lisplogo_alien_128.png" alt="Lisp logo" title="lisplogo_alien_128" width="128" height="75" class="size-full wp-image-95" /></p>
<p>You can <a href="http://common-lisp.net/project/cl-buchberger/">read more about cl-buchberger here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.superadditive.com/2007/10/19/cl-buchberger-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
