<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://www.foldr.org/~michaelw/log/theme/style/rss.css" type="text/css"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xml:lang="en">

	<channel>
		<title>Random Bits and Pieces :: programming/lisp</title>
		<link>http://www.foldr.org/~michaelw/log</link>
		<description>Michael Weber</description>
		<language>en</language>
		<lastBuildDate>Sun, 01 Nov 2009 11:30:00 GMT</lastBuildDate>
		<generator>blosxom ver.2.0</generator>


		<item>
			<title>Cocoa Apis</title>
			<link>http://www.foldr.org/~michaelw/log/programming/lisp/cocoa-apis</link>
			<guid isPermaLink="true">http://www.foldr.org/~michaelw/log/programming/lisp/cocoa-apis</guid>
			<category>http://www.foldr.org/~michaelw/log/programming/lisp/</category>
			<pubDate>Sun, 01 Nov 2009 11:30:00 GMT</pubDate>
			<content:encoded><![CDATA[
<img src="http://www.foldr.org/~michaelw/log/static/programming/lisp/lisp.png" alt="Lisp Logo (by Conrad Barsky)" />

<p><a href="http://mikelevins.livejournal.com/">Mikel Evins</a> has
  released <a href="http://mikelevins.livejournal.com/5400.html">Apis</a>,
  a sample Common
  Lisp <a href="http://developer.apple.com/cocoa/">Cocoa</a>
  application
  using <a href="http://www.clozure.com/clozurecl.html">CCL</a>'s
  Cocoa bridge.  Obligatory screenshot:
</p>

<img src="http://www.foldr.org/~michaelw/log/static/programming/lisp/apis.png" alt="Apis screenshot" 
     class="center" />

<p>For what it's worth, Mikel also
  provides <a href="http://mikelevins.livejournal.com/5247.html">Atta</a>,
  which is a similar project but based
  on <a href="http://www.iro.umontreal.ca/~gambit/">Gambit
  Scheme</a>.
</p>
]]></content:encoded>
			<comments>http://www.foldr.org/~michaelw/log/programming/lisp/cocoa-apis#writeback</comments>
		</item>

		<item>
			<title>The Next 50 Years of Lisp</title>
			<link>http://www.foldr.org/~michaelw/log/programming/lisp/the-next-50-years</link>
			<guid isPermaLink="true">http://www.foldr.org/~michaelw/log/programming/lisp/the-next-50-years</guid>
			<category>http://www.foldr.org/~michaelw/log/programming/lisp/</category>
			<pubDate>Sun, 05 Apr 2009 15:50:00 GMT</pubDate>
			<content:encoded><![CDATA[
<img src="http://www.foldr.org/~michaelw/log/static/programming/lisp/lisp.png" alt="Lisp Logo (by Conrad Barsky)" />

<p>
Today I stumbled upon
the <a href="http://ilc2009.scheming.org/">discussion forum for
ILC2009</a>.  Why did <a href="http://planet.lisp.org/">Planet
Lisp</a> not tell me before?  Slackers.
</p>
]]></content:encoded>
			<comments>http://www.foldr.org/~michaelw/log/programming/lisp/the-next-50-years#writeback</comments>
		</item>

		<item>
			<title>Some Tiny-CLOS Hackery</title>
			<link>http://www.foldr.org/~michaelw/log/programming/lisp/clos</link>
			<guid isPermaLink="true">http://www.foldr.org/~michaelw/log/programming/lisp/clos</guid>
			<category>http://www.foldr.org/~michaelw/log/programming/lisp/</category>
			<pubDate>Fri, 27 Mar 2009 23:22:00 GMT</pubDate>
			<content:encoded><![CDATA[
<img src="http://www.foldr.org/~michaelw/log/static/programming/lisp/lisp.png" alt="Lisp Logo (by Conrad Barsky)" />

<p>Some time ago, I translated Gregor Kiczales' Tiny-CLOS to Common
Lisp and Java:
        <a href="http://www.foldr.org/~michaelw/lisp/mw-tiny-clos/">MW-TINY-CLOS</a> and
        <a href="http://www.foldr.org/~michaelw/projects/jclos/">jCLOS</a>.
</p>

<p>The Common Lisp port is probably not very interesting, this was
  mostly a warm-up exercise.  Only when I was mostly finished, I found
  Kiczales' original CL (back?)port.</p>

<p class="first">For <a href="http://www.foldr.org/~michaelw/projects/jclos/">jCLOS</a>,
  package <code>jclos</code> contains all functionality.
  The <code>main</code> method contains some straight-forward example
  code, which creates an object with two slots <code>x</code>
  and <code>y</code>, an instance, and a method on
  the <code>print</code> generic function.</p>

<pre class="java"><code class="java">
</span><span class="keyword">public</span> <span class="keyword">static</span> <span class="type">void</span> <span class="function-name">main</span>(<span class="type">String</span>[] <span class="variable-name">args</span>) {
    System.out.println(<span class="string">"JCLOS booted."</span>);

    <span class="type">CLOSInstance</span> <span class="variable-name">POS</span> = defineClass(<span class="constant">null</span>, <span class="constant">null</span>, 
            Arrays.asList(<span class="keyword">new</span> <span class="type">DirectSlotDefn</span>[]{
                    <span class="keyword">new</span> <span class="type">DirectSlotDefn</span>(Symbol.intern(<span class="string">"x"</span>)),
                    <span class="keyword">new</span> <span class="type">DirectSlotDefn</span>(Symbol.intern(<span class="string">"y"</span>))
                }),
            Symbol.intern(<span class="string">"&lt;pos&gt;"</span>));
    
    System.out.println(POS);

    <span class="type">CLOSInstance</span> <span class="variable-name">pos</span> = make(POS);
    pos.setSlot(Symbol.intern(<span class="string">"x"</span>), 42);
    System.out.println(pos.slot(Symbol.intern(<span class="string">"x"</span>)));

    <span class="type">CLOSInstance</span> <span class="variable-name">print</span> = makeGeneric();
    addMethod(print,
            makeMethod(Collections.singletonList(OBJECT),
              <span class="keyword">new</span> <span class="type">StdCallable</span>() {
                  @Override
                  <span class="keyword">public</span> Object apply(<span class="type">Object</span>[] <span class="variable-name">args</span>) {
                      System.out.println(<span class="string">"'"</span> + args[1] + <span class="string">"' is an OBJECT!"</span>);
                      <span class="keyword">return</span> <span class="constant">null</span>;
                  }
              }));
    <span class="comment-delimiter">/* </span><span class="comment">... */</span>
    print.call(POS);
    print.call(pos);
}
</code></pre>

<p>I find it quite self-evident that Java is sorely missing some kind
of facility for syntactic abstraction.  The Java camp appears to
disagree, and as <a href="http://danweinreb.org/blog/">Dan
Weinreb</a> <a href="http://danweinreb.org/blog/the-international-lisp-conference-2009-succeeded">reports
from ILC2009</a>, there are even Lispers thinking that <a href="http://people.csail.mit.edu/jhbrown/macros/">macros are
a <q>net drawback</q></a>!
</p>

<p>Regarding jCLOS, I have some ideas what to do with it.  However,
  this might take a while.  Short-term, the next step should be to
  simplify the current implementation as much as possible, for example
  by getting rid of symbols and keyword arguments.  Also,
  the <q>poor-man's closure objects</q> could probably benefit from
  some clean-up.  (Incidentally, perhaps I should switch to
  Javascript, just for its support for anonymous functions.)
</p>

<p>
  Some more interesting changes involve the implementation
  of jCLOS slots (taken over from Tiny-CLOS) in terms
  of <q>fields</q>.  Other/better approaches are known for quite a while:
</p>
<blockquote>
Shigeru Chiba, Gregor Kiczales, John
    Lamping: <em><a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.32.1784">Avoiding
    Confusion in Metacircularity: The Meta-Helix</a></em>. ISOTAS
    1996: 157&ndash;172.
</blockquote>

<p>Generally, a cleaner way to avoid meta-stability and circularity
  issues is also on my list of things to look into.</p>
  
<p>I also remember a posting by Scott McKay
  about <a href="http://groups.google.com/group/comp.lang.lisp/msg/a1838258419053c7">class
  slots versus accessors</a>, which is probably also worth following
  up on (in particular in combination
  with <code><a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_chg_cl.htm">CHANGE-CLASS</a></code>
  like functionality).
</p>
]]></content:encoded>
			<comments>http://www.foldr.org/~michaelw/log/programming/lisp/clos#writeback</comments>
		</item>

		<item>
			<title>99 Bottles of Beer</title>
			<link>http://www.foldr.org/~michaelw/log/programming/lisp/99-bottles-of-beer</link>
			<guid isPermaLink="true">http://www.foldr.org/~michaelw/log/programming/lisp/99-bottles-of-beer</guid>
			<category>http://www.foldr.org/~michaelw/log/programming/lisp/</category>
			<pubDate>Fri, 06 Mar 2009 21:51:00 GMT</pubDate>
			<content:encoded><![CDATA[
<p>
  A from-scratch version of
  the <a href="http://www.99-bottles-of-beer.net/">Bottle Song</a> in Lisp:
<a href="http://www.foldr.org/~michaelw/lisp/bottle-song.lisp">bottle-song.lisp</a>.
We can see some nice features
of <a href="http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm">FORMAT</a>
in action (conditionals, relative &amp; absolute go-to, user
extensions, pluralization, radix control, case conversion, etc.), but
by far not everything that is offered.
</p>

<pre class="common-lisp"><code class="common-lisp">
<span class="comment-delimiter">;; </span><span class="comment">* clisp bottle-song.lisp
</span>
<span class="paren">(</span><span class="keyword">in-package</span> <span class="builtin">:cl-user</span><span class="paren">)</span>

<span class="paren">(</span><span class="keyword">defun</span> <span class="function-name">bottle-song</span> <span class="paren">(</span><span class="type">&amp;optional</span> <span class="paren">(</span>in-stock 99<span class="paren">)</span> <span class="paren">(</span>stream *standard-output*<span class="paren">))</span>
  <span class="comment-delimiter">;; </span><span class="comment">Original idea by Geoff Summerhayes &lt;<a href="mailto:sumrnot&#64;hotmail.com">sumrnot&#64;hotmail.com</a>&gt;
</span>  <span class="comment-delimiter">;; </span><span class="comment">Formatting idea by Fred Gilham &lt;<a href="mailto:gilham&#64;snapdragon.csl.sri.com">gilham&#64;snapdragon.csl.sri.com</a>&gt;
</span>  <span class="comment-delimiter">;; </span><span class="comment">Actual formatting &amp; minor recoding by Kent M Pitman
</span>  <span class="comment-delimiter">;;   </span><span class="comment">&lt;<a href="mailto:pitman&#64;world.std.com">pitman&#64;world.std.com</a>&gt;
</span>  <span class="comment-delimiter">;; </span><span class="comment">Redone for conformance to &lt;<a href="http://www.99-bottles-of-beer.net/">http://www.99-bottles-of-beer.net/</a>&gt;
</span>  <span class="comment-delimiter">;;   </span><span class="comment">by Michael Weber &lt;<a href="mailto:michaelw&#64;foldr.org">michaelw&#64;foldr.org</a>&gt;.
</span>  <span class="paren">(</span>format

              stream
            <span class="string">"~v{~1&amp;~0%~
             ~000000%~
             ~000000%~
             ~000000%~
            ~00000000%~
           ~:/bottles/ ~
         of beer on ~000%~
         the wall, ~001:*~
         ~99/bottles/ of ~
         beer.~1:*~%~[Go ~
         to the store and~
         ~000@* buy some ~
         more, ~/bottles/~
         ~00% of beer on ~
         the wall.~01%~:;~
         Take one down an~
         d pass it around~
         , ~999/bottles/ ~
         ~:*of beer on th~
         e wall.~002%~]~}"</span>
           <span class="paren">(</span>1+ in-stock<span class="paren">)</span>

   <span class="paren">(</span><span class="keyword">loop</span> for bottle from in-stock downto 0 collect bottle<span class="paren">)))</span>

<span class="paren">(</span><span class="keyword">defun</span> <span class="function-name">bottles</span> <span class="paren">(</span>stream arg <span class="type">&amp;optional</span> colonp atp <span class="type">&amp;rest</span> args<span class="paren">)</span>
  <span class="paren">(</span><span class="keyword">declare</span> <span class="paren">(</span>ignore atp args<span class="paren">))</span>
  <span class="paren">(</span>format stream <span class="string">"~[~:[n~;N~]o more bottles~:;~:*~A bottle~:*~P~]"</span>
          arg colonp<span class="paren">))</span>

<span class="paren">(</span>bottle-song<span class="paren">)</span>
</code></pre>

<p>Alternatively, numbers can be printed as (properly capitalized)
words with:</p>

<pre class="common-lisp"><code class="common-lisp">
<span class="paren">(</span><span class="keyword">defun</span> <span class="function-name">bottles</span> <span class="paren">(</span>stream arg <span class="type">&amp;optional</span> colonp atp <span class="type">&amp;rest</span> args<span class="paren">)</span>
  <span class="paren">(</span><span class="keyword">declare</span> <span class="paren">(</span>ignore atp args<span class="paren">))</span>
  <span class="paren">(</span>format stream <span class="string">"~[~:[n~;N~]o more bottles~:;~
                  ~:[~2:*~R~;~2:*~@(~R~)~] bottle~:*~P~]"</span>
          arg colonp<span class="paren">))</span>
</code></pre>

<blockquote>
<p>Ninety-nine bottles of beer on the wall, ninety-nine bottles of beer.<br>
Take one down and pass it around, ninety-eight bottles of beer on the wall.
</p>

<p>Ninety-eight bottles of beer on the wall, ninety-eight bottles of beer.<br>
Take one down and pass it around, ninety-seven bottles of beer on the wall.
</p>
[&hellip;]
</blockquote>
<h3><a id="99-bottles-of-beer-1" class="updatetitle">UPDATE 2009-04-08: Fame, at last!
</a><br /></h3>
<div><p>
  <a href="http://xach.com/">Zach Beane</a>  
  showed the bottle song sources (in form of a 
  <a href="http://www.flickr.com/photos/xach/3384856473/in/photostream/">Format
  Automotivator</a>) during his
  <a href="http://www.international-lisp-conference.org/2009/">ILC2009</a> <a href="http://www.xach.com/lisp/LightningILC2009.pdf">lightning
  talk</a> about the <a href="http://wigflig.com/">Wigflig</a>
  imperium!
</p>

<img class="center"
     src="http://www.foldr.org/~michaelw/log/static/programming/lisp/format-automotivator.jpg" 
     alt="Format Automotivator Poster (by Zach Beane)">
</div>

]]></content:encoded>
			<comments>http://www.foldr.org/~michaelw/log/programming/lisp/99-bottles-of-beer#writeback</comments>
		</item>

		<item>
			<title>An Awesome Lisp Library</title>
			<link>http://www.foldr.org/~michaelw/log/programming/lisp/rainer-joswigs-lisp-library</link>
			<guid isPermaLink="true">http://www.foldr.org/~michaelw/log/programming/lisp/rainer-joswigs-lisp-library</guid>
			<category>http://www.foldr.org/~michaelw/log/programming/lisp/</category>
			<pubDate>Wed, 14 Jan 2009 22:49:00 GMT</pubDate>
			<content:encoded><![CDATA[
<img src="http://www.foldr.org/~michaelw/log/static/programming/lisp/lisp.png" alt="Lisp Logo (by Conrad Barsky)" />

<p><a href="http://lispm.dyndns.org/">Rainer Joswig</a> has an
  awesome <a href="http://www.librarything.com/catalog_bottom.php?tag=lisp&view=lispm">library
  of Lisp books</a>!
</p>
]]></content:encoded>
			<comments>http://www.foldr.org/~michaelw/log/programming/lisp/rainer-joswigs-lisp-library#writeback</comments>
		</item>

	</channel>
</rss>
