<?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>It Seemed Like a Good Idea at the Time &#187; lisp</title>
	<atom:link href="http://blog.willdonnelly.net/category/lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.willdonnelly.net</link>
	<description>Coding, Mostly</description>
	<lastBuildDate>Fri, 20 Aug 2010 15:33:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Announcing the UCL Portability Libraries</title>
		<link>http://blog.willdonnelly.net/2010/08/20/announcing-the-ucl-portability-libraries/</link>
		<comments>http://blog.willdonnelly.net/2010/08/20/announcing-the-ucl-portability-libraries/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 15:33:00 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[scheme]]></category>
		<category><![CDATA[ucl]]></category>

		<guid isPermaLink="false">http://blog.willdonnelly.net/?p=400</guid>
		<description><![CDATA[I spent the last year learning Haskell, and it is a ver [...]]]></description>
			<content:encoded><![CDATA[<p>I spent the last year learning Haskell, and it is a very cool language. That said, I get the feeling that it also gains a gigantic competitive advantage from <a href="http://hackage.haskell.org/trac/hackage/wiki/CabalInstall">cabal-install</a> and <a href="http://hackage.haskell.org/packages/hackage.html">HackageDB</a>. Package repositories and install tools for languages are <a href="http://www.cpan.org/">not</a><a href="http://pypi.python.org/pypi"> a</a> <a href="http://rubygems.org/">new</a> <a href="http://snow.iro.umontreal.ca/">thing</a>, but it was Hackage that made me realize how effectively a common package infrastructure can help to raise the popularity of a language.</p>
<p>And here's the thing: to a sufficiently fuzzy approximation, all the R6RS Schemes out there are interchangeable. They all offer a foreign function interface with roughly the same capabilities, they all offer the ability to launch and control subprocesses, and just about anything else can be built up from there. All of the cool things that can be built from these primitives, there is no fundamental reason they can't be portable.</p>
<p>So in April I started working on a set of portability packages, followed by an install tool, followed by a web-based package upload and browsing interface. And now it's all sufficiently done that I feel like I should release it.</p>
<p><a href="http://ucl.willdonnelly.net/">So here you go</a>.</p>
<h2>Caveats</h2>
<p>It supports <a href="http://ikarus-scheme.org/">Ikarus</a>, <a href="http://www.larcenists.org/">Larceny</a>, <a href="http://mosh.monaos.org/">Mosh</a>, <a href="http://racket-lang.org/">Racket</a>, and <a href="http://code.google.com/p/ypsilon/">Ypsilon</a>, at least on my machine.</p>
<p>The install tool could certainly use more features, like a package upgrade ability, code precompilation for the various Schemes, and complex version constraints on packages. The web interface is horrible code, and I'm just happy it seems to work as well as it does.</p>
<p>But what I am proud of are the simple but extensible package format, with myriad available extension points for new features, the simple repository format which allows anyone to start serving up packages if they don't like my offering, and the libraries which allow FFI and process manipulation to operate identically across Schemes.</p>
<h2>Similar Projects</h2>
<p>This code doesn't exist in a vacuum, and there are other projects whose scope overlaps with mine.</p>
<p>The most noticeable, to me, is Marco Maggi's <a href="http://github.com/marcomaggi/nausicaa">Nausicaa</a>, a gargantuan library distribution for R6RS Schemes. I regret to say that I have no experience using it, but the sheer number of libraries is impressive. I would like nothing more than to see some of those libraries available through UCL Install at some point.</p>
<p>The only other R6RS package manager that I have heard of is <a href="http://rotty.yi.org/software/dorodango/">Dorodango</a>. It does not seem to have been officially released yet, and if I understand the documentation correctly, it only supports Ikarus and Ypsilon at this time. It does have an upgrade command, unlike UCL Install at this point.  I envy the awesome choice of name, and I look forward to seeing what the author does with this one in the future.</p>
<p>Finally we come to <a href="http://snow.iro.umontreal.ca/">Snowfort</a>, an older attempt at a Scheme packaging system. I do not believe it is R6RS compatible, as it defines its own module system, and it appears to have no FFI or other portability layers, so I believe packages are limited to pure Scheme code. I would like to look at either manually or automatically porting some of these packages at some point, if the authors are amenable.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;headline=Announcing+the+UCL+Portability+Libraries" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Announcing+the+UCL+Portability+Libraries&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2010/08/20/announcing-the-ucl-portability-libraries/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Fixing Broken Macros with Eval and Quasiquote</title>
		<link>http://blog.willdonnelly.net/2009/03/21/fixing-broken-macros-with-eval-and-quasiquote/</link>
		<comments>http://blog.willdonnelly.net/2009/03/21/fixing-broken-macros-with-eval-and-quasiquote/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 01:20:36 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[macro]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=210</guid>
		<description><![CDATA[Recently, I found myself needing to deal with a "conven [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I found myself needing to deal with a "convenience" macro, which quoted several of its arguments for me before passing them along to the real function.  Unfortunately, only the macro was exported from the library, and I was unable to access the base function.</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> convenient<span style="color: #66cc66;">-</span>function<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ arg1 arg2<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>much<span style="color: #66cc66;">-</span>harder<span style="color: #66cc66;">-</span>function 'arg1 'arg2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>How useful.  To save me a handful of quotes, I lose the ability to programmatically generate my arguments.</p>
<p>As I was loath to reimplement the entire library just to regain that ability, I looked for another solution.  Thankfully, I found one.</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>much<span style="color: #66cc66;">-</span>harder<span style="color: #66cc66;">-</span>function arg1 arg2<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>eval `<span style="color: #66cc66;">&#40;</span>convenient<span style="color: #66cc66;">-</span>function ,arg1 ,arg2<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>environment '<span style="color: #66cc66;">&#40;</span>convenient<span style="color: #66cc66;">-</span>lib<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>As far as I can tell, this circumvents the macro's quoting features entirely to allow me to pass in a dynamically generated symbol.  While it won't work with functions which modify the environment, it worked well in my case, and allowed me to move on to more interesting code.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F&amp;title=Fixing+Broken+Macros+with+Eval+and+Quasiquote" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F&amp;title=Fixing+Broken+Macros+with+Eval+and+Quasiquote" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F&amp;title=Fixing+Broken+Macros+with+Eval+and+Quasiquote" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F&amp;headline=Fixing+Broken+Macros+with+Eval+and+Quasiquote" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Fixing+Broken+Macros+with+Eval+and+Quasiquote&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Fixing+Broken+Macros+with+Eval+and+Quasiquote&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Fixing+Broken+Macros+with+Eval+and+Quasiquote&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Fixing+Broken+Macros+with+Eval+and+Quasiquote&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Fixing+Broken+Macros+with+Eval+and+Quasiquote&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F&amp;title=Fixing+Broken+Macros+with+Eval+and+Quasiquote&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F21%2Ffixing-broken-macros-with-eval-and-quasiquote%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/03/21/fixing-broken-macros-with-eval-and-quasiquote/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SRFI-0 for Detecting Scheme Implementation</title>
		<link>http://blog.willdonnelly.net/2009/03/14/srfi-0-for-detecting-scheme-implementation/</link>
		<comments>http://blog.willdonnelly.net/2009/03/14/srfi-0-for-detecting-scheme-implementation/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 23:44:11 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[scheme]]></category>
		<category><![CDATA[srfi-0]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=202</guid>
		<description><![CDATA[I found out earlier today that SRFI-0 can be used to de [...]]]></description>
			<content:encoded><![CDATA[<p>I found out earlier today that SRFI-0 can be used to determine the host Scheme in some cases.  Here is the result of my testing, in case someone finds it useful:</p>
<p>No SRFI-0 by default:</p>
<ul>
<li>mzscheme</li>
<li>ikarus</li>
<li>scheme48</li>
</ul>
<p>Name exported for cond-expand:</p>
<table border="0">
<thead>
<tr>
<td><b>Scheme Name&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
<td><b>SRFI-0 Feature Name</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>CHICKEN</td>
<td>chicken</td>
</tr>
<tr>
<td>Guile</td>
<td>guile</td>
</tr>
<tr>
<td>Bigloo</td>
<td>bigloo</td>
</tr>
<tr>
<td>Gambit</td>
<td>gambit</td>
</tr>
<tr>
<td>MIT Scheme</td>
<td>mit</td>
</tr>
<tr>
<td>Gauche</td>
<td>gauche</td>
</tr>
</tbody>
</table>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F&amp;title=SRFI-0+for+Detecting+Scheme+Implementation" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F&amp;title=SRFI-0+for+Detecting+Scheme+Implementation" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F&amp;title=SRFI-0+for+Detecting+Scheme+Implementation" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F&amp;headline=SRFI-0+for+Detecting+Scheme+Implementation" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=SRFI-0+for+Detecting+Scheme+Implementation&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=SRFI-0+for+Detecting+Scheme+Implementation&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=SRFI-0+for+Detecting+Scheme+Implementation&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=SRFI-0+for+Detecting+Scheme+Implementation&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=SRFI-0+for+Detecting+Scheme+Implementation&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F&amp;title=SRFI-0+for+Detecting+Scheme+Implementation&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fsrfi-0-for-detecting-scheme-implementation%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/03/14/srfi-0-for-detecting-scheme-implementation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Runtime Scheme Detection</title>
		<link>http://blog.willdonnelly.net/2009/03/14/runtime-scheme-detection/</link>
		<comments>http://blog.willdonnelly.net/2009/03/14/runtime-scheme-detection/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 21:33:32 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[portability]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=191</guid>
		<description><![CDATA[I really want my code to be "write once, run anywhere", [...]]]></description>
			<content:encoded><![CDATA[<p>I really want my code to be "write once, run anywhere", at least as far as Schemes go.  R6RS library features make strides toward that goal.  Only, there's not many R6RS Schemes.  Since there are a whole lot of R5RS ones, I'd like to include R5RS in the portability fun.</p>
<p>In many cases, enough functionality appears in all major implementations to make some major steps toward portability.  So a while back, I decided to get a few things out of the way (you know, processes, FFI, things like that).</p>
<p>To make simple, portable libraries, we need to find out some details about the Scheme implementation the code is running under.  Unfortunately, there is no standard way to do this.  We could just call a function and see if it worked, but then we throw an error, and there's no standard way to trap those in R5RS.  And even if a function of the given name existed, we still don't know what arguments it takes, because that differs too.</p>
<p>So we're left with some sort of indirect detection method,  guessing the implementation based on a bunch of unrelated tests.</p>
<p>So I gathered a list of as many nonstandardized/undefined behaviours as possible (mainly from <a title="Scheme Implementation Choices" href="http://web.mit.edu/~axch/www/scheme/choices.html">this table</a>, and grepping the R5RS spec for the word "undefined").  Then I filtered those differences down to a bunch of tests that won't error out.  Then I took the tests that gave meaningful results, and because I had enough of those to be picky, I took only tests which fit on a single line.</p>
<p>The resulting set of 20 tests generates a sort of "signature" -- a list of twenty boolean values that identifies the host Scheme.</p>
<p>Currently the code works on:</p>
<ul>
<li>MzScheme</li>
<li>CHICKEN</li>
<li>Guile</li>
<li>Bigloo</li>
<li>Gambit</li>
<li>Ikarus</li>
<li>Scheme48</li>
<li>MIT Scheme</li>
<li>Gauche</li>
</ul>
<p>This is actually a list of all the implementations I have installed right now, and other implementations can be supported just by adding another line to the signatures list.</p>
<p>On Scheme implementations which provide a compiled and an interpreted mode, only interpreted has been tested (I don't really know how to use a compiled Scheme, so I didn't).  Some Schemes have different behaviour interpreted and compiled, so caution should be used there.</p>
<p>Enough talk, here's the code:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;;</span><br />
<span style="color: #808080; font-style: italic;">;;; DETECT</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; A set of functions to allow an interpreted Scheme</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; &nbsp;program to determine the implementation it is</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; &nbsp;running under.</span><br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; DETECT:SIGNATURE</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Assemble a signature for the current</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Scheme implementation.</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>detect:signature<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: exact-sqrt</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exact?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">sqrt</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: exact-times-zero</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exact?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">3.1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: exact-div-zero</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exact?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">4.7</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: exact-rationals</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exact?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: case-sensitive</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> 'a 'A<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: promises-are-thunks</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">procedure?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Do strings made from numbers less than 1 omit the 0?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string=?</span> <span style="color: #ff0000;">&quot;.5&quot;</span> <span style="color: #66cc66;">&#40;</span>number<span style="color: #66cc66;">-&gt;</span>string <span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: literal-rationals</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">number?</span> <span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">-&gt;</span>number <span style="color: #ff0000;">&quot;1/2&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; AXCH: literal-complexes</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">number?</span> <span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">-&gt;</span>number <span style="color: #ff0000;">&quot;1+i&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Is the empty string eqv to itself?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; How about the empty vector?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> '#<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> '#<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; A non-empty string?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Does SET! have a constant return value?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>x <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> x 'asd<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Is it equal to other undefined things?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">for-each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span> #t<span style="color: #66cc66;">&#41;</span> '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>x <span style="color: #cc66cc;">123</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> x <span style="color: #cc66cc;">321</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Are negative and positive inexact zero the same?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> <span style="color: #66cc66;">+</span><span style="color: #cc66cc;">0.0</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">+</span><span style="color: #cc66cc;">0.0</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> <span style="color: #66cc66;">+</span><span style="color: #cc66cc;">0.0</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Is the default vector filled with zeroes?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">make-vector</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> '#<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Is the default vector filled with falses?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">make-vector</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> '#<span style="color: #66cc66;">&#40;</span>#f #f #f #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Vector-fill returns a vector?</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector-fill!</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">make-vector</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; DETECT:KNOWN-SIGNATURES</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; A precalculated list of signatures for all supported</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; &nbsp;Scheme implementations.</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> detect:known<span style="color: #66cc66;">-</span>signatures<br />
'<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>mzscheme &nbsp; <span style="color: #66cc66;">&#40;</span>#t #t #t #t #f #f #f #t #t #f #f #f #t #t #f #f #f #t #f #t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>chicken &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>#f #f #f #f #f #f #f #t #f #f #f #f #t #t #f #t #t #f #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>guile &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>#f #t #f #t #f #f #f #t #t #t #f #f #t #t #f #f #t #f #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>bigloo &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>#f #f #f #f #f #t #f #f #f #f #f #f #t #t #f #t #t #f #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>gambit &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>#t #t #t #t #f #f #t #t #t #f #f #f #t #t #f #f #f #t #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>ikarus &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>#f #f #f #t #f #t #f #t #f #f #f #f #t #f #f #t #t #t #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>scheme48 &nbsp; <span style="color: #66cc66;">&#40;</span>#f #f #f #t #t #t #f #t #t #t #t #t #t #t #t #t #t #f #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>mit<span style="color: #66cc66;">-</span>scheme <span style="color: #66cc66;">&#40;</span>#t #t #t #t #t #f #t #t #t #f #t #f #f #f #f #t #t #f #t #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>gauche &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>#f #f #f #t #f #f #f #t #t #f #f #f #f #f #f #t #t #f #f #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; DETECT:MATCH-SIGNATURE</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Determine the name of the current Scheme implementation</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; &nbsp;by checking the signature returned by DETECT:SIGNATURE</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; &nbsp;against a table of known signatures.</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>detect:match<span style="color: #66cc66;">-</span>signature<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>signature <span style="color: #66cc66;">&#40;</span>detect:signature<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Loop over the DETECT:KNOWN-SIGNATURES list</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> test <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>siglist detect:known<span style="color: #66cc66;">-</span>signatures<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> siglist<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Return 'UNKNOWN if we're stumped</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; 'unknown<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>testsig <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> siglist<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cadr</span> testsig<span style="color: #66cc66;">&#41;</span> signature<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> testsig<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>test <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> siglist<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; DETECT:NAME</span><br />
<span style="color: #808080; font-style: italic;">;; Memoized form of DETECT:MATCH-SIGNATURE</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> detect:name<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>memo #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> memo<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> memo <span style="color: #66cc66;">&#40;</span>detect:match<span style="color: #66cc66;">-</span>signature<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; memo<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Obviously, only the memoized DETECT:NAME is meant for general use, since a program generally won't the see the host changing as it runs, and repeatedly calculating the name would be inefficient.  I don't actually have much experience with Scheme, so the DETECT:MATCH-SIGNATURE function could probably be written more efficiently, but it works.</p>
<p>Anyway, I hope that someone finds this to be useful.  I have used it to write the beginnings of a portable process library.  More on that after I get around to polishing it up a bit more.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F&amp;title=Runtime+Scheme+Detection" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F&amp;title=Runtime+Scheme+Detection" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F&amp;title=Runtime+Scheme+Detection" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F&amp;headline=Runtime+Scheme+Detection" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Runtime+Scheme+Detection&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Runtime+Scheme+Detection&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Runtime+Scheme+Detection&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Runtime+Scheme+Detection&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Runtime+Scheme+Detection&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F&amp;title=Runtime+Scheme+Detection&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F03%2F14%2Fruntime-scheme-detection%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/03/14/runtime-scheme-detection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scheme Load Return Values</title>
		<link>http://blog.willdonnelly.net/2009/01/15/scheme-load-return-values/</link>
		<comments>http://blog.willdonnelly.net/2009/01/15/scheme-load-return-values/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 03:21:14 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[bigloo]]></category>
		<category><![CDATA[chicken]]></category>
		<category><![CDATA[gambit]]></category>
		<category><![CDATA[guile]]></category>
		<category><![CDATA[mit-scheme]]></category>
		<category><![CDATA[mzscheme]]></category>
		<category><![CDATA[stklos]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=172</guid>
		<description><![CDATA[Shortly after finishing my previous post, I began to wo [...]]]></description>
			<content:encoded><![CDATA[<p>Shortly after finishing my previous post, I began to wonder if maybe some of the features I had requested were available already.  I was pleasantly surprised.</p>
<p>Implementations tested were:</p>
<ul>
<li><a href="http://www.plt-scheme.org/software/mzscheme/">MzScheme</a></li>
<li><a href="http://www-sop.inria.fr/mimosa/fp/Bigloo/">Bigloo</a></li>
<li><a href="http://www.gnu.org/software/guile/guile.html">Guile</a></li>
<li><a href="http://www.call-with-current-continuation.org/">Chicken</a></li>
<li><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page">Gambit</a></li>
<li><a href="http://groups.csail.mit.edu/mac/projects/scheme/">MIT Scheme</a></li>
<li><a href="http://www.stklos.net/">STklos</a></li>
</ul>
<p>Bad news first.  In my hour or so of testing, I was unable to find any way to directly return values from a loaded file in Guile, Gambit, and STklos.</p>
<p>On the other hand, that means that four of the seven implementations that I tested <strong>could</strong> return values.</p>
<p>MzScheme and MIT Scheme both return the last form, whatever it was.  If the last form was a DEFINE statement, MzScheme returns nothing, and MIT Scheme returns the identifier that was defined.</p>
<p>Bigloo doesn't seem to return anything usable, but it does <strong>print</strong> the results of intermediate evaluations, and claims to return the result of the last evaluation.  This may indeed be true, but in my testing I was unable to get it to return anything other than the path of the just-loaded file.</p>
<p>Chicken, however, was an unqualified success.  Although it is true that at first it returns nothing from its LOAD function, it provides a brilliant little mechanism to fix that.  The LOAD function, in addition to taking a filename, will also take an optional argument called EVALPROC, which is called repeatedly with each form from the loaded file.  This fact, combined with a little closure magic, ends us up with this:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>load<span style="color: #66cc66;">-</span><span style="color: #b1b100;">return</span> file<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">return</span> '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">load</span> file<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exp</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list?</span> <span style="color: #b1b100;">exp</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list-ref</span> <span style="color: #b1b100;">exp</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> '<span style="color: #b1b100;">define</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>eval <span style="color: #b1b100;">exp</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list-ref</span> <span style="color: #b1b100;">exp</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>eval <span style="color: #b1b100;">exp</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">reverse</span> <span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>This function calls the LOAD function, but passes it its own evaluation procedure, which will assemble a list of values when called, as well as evaluating each expression.</p>
<p>After seeing the beautiful and elegant way in which Chicken Scheme allows the user to dynamically alter the behaviour of the LOAD function at runtime, I feel like I should alter my recommendation for modifying that behaviour.  Chicken has, I believe, found the best possible way to implement such functionality: have a reasonable default, but allow people to override it if they wish.  Simple, elegant, and powerful: exactly like the language itself.  Bravo, Chicken.</p>
<p>Bravo.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F&amp;title=Scheme+Load+Return+Values" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F&amp;title=Scheme+Load+Return+Values" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F&amp;title=Scheme+Load+Return+Values" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F&amp;headline=Scheme+Load+Return+Values" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Scheme+Load+Return+Values&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Scheme+Load+Return+Values&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Scheme+Load+Return+Values&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Scheme+Load+Return+Values&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Scheme+Load+Return+Values&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F&amp;title=Scheme+Load+Return+Values&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F01%2F15%2Fscheme-load-return-values%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/01/15/scheme-load-return-values/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Foreign Function Interface for Ikarus Using SoLoad</title>
		<link>http://blog.willdonnelly.net/2008/12/14/a-foreign-function-interface-for-ikarus-using-soload/</link>
		<comments>http://blog.willdonnelly.net/2008/12/14/a-foreign-function-interface-for-ikarus-using-soload/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 06:21:56 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[soload]]></category>
		<category><![CDATA[ffi]]></category>
		<category><![CDATA[ikarus]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=117</guid>
		<description><![CDATA[A while back I wrote a foreign function server called S [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote a foreign function <a href="http://willdonnelly.wordpress.com/2008/08/30/the-soload-foreign-function-server-part-i-an-introduction/">server</a> <a href="http://willdonnelly.wordpress.com/2008/09/12/the-soload-foreign-function-server-part-ii-basic-usage/">called</a> <a href="http://willdonnelly.wordpress.com/2008/09/15/the-soload-foreign-function-server-part-iii-intermediate-usage/">SoLoad</a>.  It is intended for situations where a regular FFI, for whatever reason, is not available to you, but the permissions necessary to run and communicate with programs are available.</p>
<p>Once this was in place, I proceeded to write some code to take advantage of my program, and provide rudimentary C function capabilities to the Ikarus scheme implementation.  I got most of the code done, implementing portable type conversion functions, an implementation-independent interface to encapsulate the initialization and communication code, and all the little macros necessary to make the FFI easy to use.  It had its bugs, but it worked pretty well.  Well enough, at least, to create a window using SDL, and then close it again.</p>
<p>And then I just sort of forgot.  Somehow, after getting it all to work and provide a basic level of C library integration to Ikarus, I just wandered off and allowed myself to get involved in other projects.</p>
<p>Today, I was looking through my projects folder, and happened to notice the code I had previously forgotten.  Working under the assumption that someone could probably find a use for it, I decided that I would clean it up and post it online.</p>
<p>It required considerably less cleaning that I had expected.</p>
<h2>Basic Structure of the Scheme-&gt;SoLoad Link</h2>
<p>A major design goal in this project was designing it in a way that would allow it to be easily ported to a variety of Scheme implementations and communication channels.  The design I ultimately settled on was as follows:</p>
<p>There is one function, SOLOAD-INIT, which handles essentially all of the necessary setup, communication, and teardown code associated with using SoLoad.  When called, it is passed the path to the SoLoad executable, and calls it.  It then returns a pair, whose CAR is a function to send data to SoLoad and return whatever data SoLoad sends back, and whose CDR is a function that will tell SoLoad to exit and perform any other teardown functions that may be necessary.</p>
<p>Its implementation for Ikarus looks like this:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>import <span style="color: #66cc66;">&#40;</span>ikarus<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<span style="color: #808080; font-style: italic;">;;; soload-init</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; Starts an instance of SoLoad</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; Returns a cons cell containing two functions:</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; &nbsp; car: Send a command to SoLoad, return the output.</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; &nbsp; cdr: Kill SoLoad and close all sockets.</span><br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>init soload<span style="color: #66cc66;">-</span>path<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #808080; font-style: italic;">;; Start SoLoad, and bind its input, output, and error ports.</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>let<span style="color: #66cc66;">-</span>values <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>pid ip op errp<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>process soload<span style="color: #66cc66;">-</span>path <span style="color: #ff0000;">&quot;stdin&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">;; Transcode the ports we'll be using.</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>soload<span style="color: #66cc66;">-</span>in &nbsp;<span style="color: #66cc66;">&#40;</span>transcoded<span style="color: #66cc66;">-</span>port op <span style="color: #66cc66;">&#40;</span>native<span style="color: #66cc66;">-</span>transcoder<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>soload<span style="color: #66cc66;">-</span>out <span style="color: #66cc66;">&#40;</span>transcoded<span style="color: #66cc66;">-</span>port ip <span style="color: #66cc66;">&#40;</span>native<span style="color: #66cc66;">-</span>transcoder<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">;; Send commands to SoLoad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>command<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>port<span style="color: #66cc66;">-</span>closed? soload<span style="color: #66cc66;">-</span>out<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Make sure it's open</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>put<span style="color: #66cc66;">-</span><span style="color: #b1b100;">string</span> soload<span style="color: #66cc66;">-</span>out command<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; Send the command</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">newline</span> soload<span style="color: #66cc66;">-</span>out<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; Newline</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>flush<span style="color: #66cc66;">-</span><span style="color: #b1b100;">output-port</span> soload<span style="color: #66cc66;">-</span>out<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; Flush the port</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>port<span style="color: #66cc66;">-</span>closed? soload<span style="color: #66cc66;">-</span>in<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; Make sure it's open</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>line soload<span style="color: #66cc66;">-</span>in<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; Get the output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">;; Kill SoLoad and close the ports</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>port<span style="color: #66cc66;">-</span>closed? soload<span style="color: #66cc66;">-</span>out<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Make sure it's open</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>put<span style="color: #66cc66;">-</span><span style="color: #b1b100;">string</span> soload<span style="color: #66cc66;">-</span>out <span style="color: #ff0000;">&quot;exit<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #808080; font-style: italic;">; Tell it to close</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>flush<span style="color: #66cc66;">-</span><span style="color: #b1b100;">output-port</span> soload<span style="color: #66cc66;">-</span>out<span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #808080; font-style: italic;">; Flush output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>close<span style="color: #66cc66;">-</span>port soload<span style="color: #66cc66;">-</span>out<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; Close the port</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>port<span style="color: #66cc66;">-</span>closed? soload<span style="color: #66cc66;">-</span>in<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; Make sure it's open</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>close<span style="color: #66cc66;">-</span>port soload<span style="color: #66cc66;">-</span>in<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Close the port</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>port<span style="color: #66cc66;">-</span>closed? errp<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Make sure it's open</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>close<span style="color: #66cc66;">-</span>port errp<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; Close the port</span></div></div>
<p>And that concludes the implementation-dependent portion of the interface.  All of the code above this level is (hopefully) completely independent of whatever particular Scheme it is running on.</p>
<h2>Type Conversion</h2>
<p>The next important part of the Ikarus/SoLoad FFI is the conversion between Scheme native types, and their text-based representation.</p>
<p>This consists of a myriad of small little functions, to escape/unescape strings, convert numbers, and flatten lists into a single string.  They are each easy to implement, and should be entirely portable Scheme code.</p>
<p>All together, they run a little long, but I may as well post them here as well:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; soload-escape</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Escape text so SoLoad will read it properly.</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>escape text<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> text <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; soload-unescape</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Remove the escaping from text that SoLoad returns.</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>unescape text<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>list<span style="color: #66cc66;">-&gt;</span>string<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">reverse</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">reverse</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">-&gt;</span>list text<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; Remove quotation marks</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; native-&gt;soload</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Converts a native type to a</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; string representation that can</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; be passed to SoLoad.</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>native<span style="color: #66cc66;">-&gt;</span>soload type value<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">case</span> type<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>int float double long short<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint8 sint8 uint16 sint16<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint32 sint32 uint64 sint64<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ushort sshort uint sint<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ulong slong char uchar<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; schar<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>number<span style="color: #66cc66;">-&gt;</span>string value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string</span> char<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>escape value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>pointer void<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> value<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>void<span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span> <span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #808080; font-style: italic;">;; soload-&gt;native</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; Converts a SoLoad string</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; into a native type.</span><br />
<span style="color: #808080; font-style: italic;">;;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-&gt;</span>native type value<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">case</span> type<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>int float double long short<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint8 sint8 uint16 sint16<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint32 sint32 uint64 sint64<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ushort sshort uint sint<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ulong slong char uchar<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; schar<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">-&gt;</span>number value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string</span> char<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>unescape value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>pointer void<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> value<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>void<span style="color: #66cc66;">&#41;</span> #t<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span> #f<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:native<span style="color: #66cc66;">-&gt;</span>soload types values<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> types<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>native<span style="color: #66cc66;">-&gt;</span>soload <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> types<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:native<span style="color: #66cc66;">-&gt;</span>soload <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> types<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:soload<span style="color: #66cc66;">-&gt;</span>native types values<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> types<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-&gt;</span>native <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> types<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:soload<span style="color: #66cc66;">-&gt;</span>native <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> types<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>flatten strings<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>apply <span style="color: #b1b100;">string-append</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot; &quot;</span> element<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strings<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<h2>Wrapping It All Up</h2>
<p>These functions technically provide all the functionality required to use SoLoad from within Ikarus, but they lack a little something.  What they need now is to be made easy.  It should be possible to declare a function such that it just works from anywhere in your program, with no need to know that it's calling a helper behind the scenes.</p>
<p>This is possibly the most involved portion of the interface, because it requires individually wrapping every function of SoLoad, and then adding a few macros to neaten things up.  In the end, though, I think it works out well:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> soload<span style="color: #66cc66;">-</span>process #f<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> soload<span style="color: #66cc66;">-</span>path <span style="color: #ff0000;">&quot;soload&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>set<span style="color: #66cc66;">-</span>path path<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> soload<span style="color: #66cc66;">-</span>path path<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send command<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> soload<span style="color: #66cc66;">-</span>process #f<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> soload<span style="color: #66cc66;">-</span>process <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>init soload<span style="color: #66cc66;">-</span>path<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> soload<span style="color: #66cc66;">-</span>process<span style="color: #66cc66;">&#41;</span> command<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>kill<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> soload<span style="color: #66cc66;">-</span>process #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> soload<span style="color: #66cc66;">-</span>process<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> soload<span style="color: #66cc66;">-</span>process #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>library path<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot;open &quot;</span> path<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>fn<span style="color: #66cc66;">-</span><span style="color: #b1b100;">load</span> library name rtype atypes<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span><br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;load &quot;</span> library <span style="color: #ff0000;">&quot; &quot;</span> name <span style="color: #ff0000;">&quot; &quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>symbol<span style="color: #66cc66;">-&gt;</span>string rtype<span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot; &quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>number<span style="color: #66cc66;">-&gt;</span>string <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> atypes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>flatten <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> symbol<span style="color: #66cc66;">-&gt;</span>string atypes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>fn<span style="color: #66cc66;">-</span>call function rtype atypes args<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-&gt;</span>native rtype<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">&quot;call &quot;</span> function<br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>flatten<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:native<span style="color: #66cc66;">-&gt;</span>soload atypes args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>import definitions<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot;def &quot;</span> definitions<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>type<span style="color: #66cc66;">-</span><span style="color: #b1b100;">define</span> name . types<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot;type &quot;</span> name <span style="color: #ff0000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>number<span style="color: #66cc66;">-&gt;</span>string <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> types<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>flatten <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> symbol<span style="color: #66cc66;">-&gt;</span>string types<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>type<span style="color: #66cc66;">-</span>create name . args<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot;new &quot;</span> name <span style="color: #ff0000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>flatten <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:native<span style="color: #66cc66;">-&gt;</span>soload types args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>delete name pointer<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> <span style="color: #ff0000;">&quot;delete &quot;</span> name <span style="color: #ff0000;">&quot; &quot;</span> pointer<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> soload<span style="color: #66cc66;">-</span>function<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ library name <span style="color: #66cc66;">&#40;</span>atypes ...<span style="color: #66cc66;">&#41;</span> rtype<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>function <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>fn<span style="color: #66cc66;">-</span><span style="color: #b1b100;">load</span> library name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'rtype '<span style="color: #66cc66;">&#40;</span>atypes ...<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> arguments<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>fn<span style="color: #66cc66;">-</span>call function 'rtype<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'<span style="color: #66cc66;">&#40;</span>atypes ...<span style="color: #66cc66;">&#41;</span> arguments<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ library name <span style="color: #66cc66;">&#40;</span>atypes ...<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function library name <span style="color: #66cc66;">&#40;</span>atypes ...<span style="color: #66cc66;">&#41;</span> void<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ library name rtype<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function library name <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> rtype<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ library name<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function library name <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> void<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; Warning! SOLOAD-TYPE does not delete the stuff</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; that it creates. &nbsp;It will stick around till</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp; SoLoad is closed.</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> soload<span style="color: #66cc66;">-</span>type<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ name types ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>type <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>type<span style="color: #66cc66;">-</span><span style="color: #b1b100;">define</span> name types ...<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> arguments<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>send<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">&quot;new &quot;</span> name <span style="color: #ff0000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>flatten<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>:native<span style="color: #66cc66;">-&gt;</span>soload '<span style="color: #66cc66;">&#40;</span>types ...<span style="color: #66cc66;">&#41;</span> arguments<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<h2>Using It</h2>
<p>Along with a working executable of SoLoad, this code should be all that is needed to use C libraries from within Ikarus.  I tested it roughly 5 minutes ago, so I'm fairly certain it works.  A working example, assuming all the previous code is in a file called "ikarus-soload.ss", with the soload executable (or a symlink) in the same directory, is as follows:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">load</span> <span style="color: #ff0000;">&quot;ikarus-soload.ss&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>set<span style="color: #66cc66;">-</span>path <span style="color: #ff0000;">&quot;./soload&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<span style="color: #808080; font-style: italic;">;;; Math Check</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; Test the value of sin for progressively closer values of pi.</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; Should return numbers moving closer to 0</span><br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; Import the library</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> libm <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>library <span style="color: #ff0000;">&quot;/lib/libm.so.6&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">;; Import the function</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> s<span style="color: #66cc66;">-</span><span style="color: #b1b100;">sin</span> <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function libm <span style="color: #ff0000;">&quot;sin&quot;</span> <span style="color: #66cc66;">&#40;</span>double<span style="color: #66cc66;">&#41;</span> double<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">;; Do some tests</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">newline</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>pretty<span style="color: #66cc66;">-</span>print <span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">-</span><span style="color: #b1b100;">sin</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>pretty<span style="color: #66cc66;">-</span>print <span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">-</span><span style="color: #b1b100;">sin</span> <span style="color: #cc66cc;">3.1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>pretty<span style="color: #66cc66;">-</span>print <span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">-</span><span style="color: #b1b100;">sin</span> <span style="color: #cc66cc;">3.14</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>pretty<span style="color: #66cc66;">-</span>print <span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">-</span><span style="color: #b1b100;">sin</span> <span style="color: #cc66cc;">3.141</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<span style="color: #808080; font-style: italic;">;;; SDL Test</span><br />
<span style="color: #808080; font-style: italic;">;;; &nbsp; Load SDL, create a window, then quit</span><br />
<span style="color: #808080; font-style: italic;">;;;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; Load the library</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> lib<span style="color: #66cc66;">-</span>sdl<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>library <span style="color: #ff0000;">&quot;/usr/lib/libSDL.so&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">;; Load a bunch of functions</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>init<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function lib<span style="color: #66cc66;">-</span>sdl <span style="color: #ff0000;">&quot;SDL_Init&quot;</span> <span style="color: #66cc66;">&#40;</span>uint32<span style="color: #66cc66;">&#41;</span> int<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>quit<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function lib<span style="color: #66cc66;">-</span>sdl <span style="color: #ff0000;">&quot;SDL_Quit&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>set<span style="color: #66cc66;">-</span>video<span style="color: #66cc66;">-</span>mode<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function lib<span style="color: #66cc66;">-</span>sdl <span style="color: #ff0000;">&quot;SDL_SetVideoMode&quot;</span> <span style="color: #66cc66;">&#40;</span>int int int uint32<span style="color: #66cc66;">&#41;</span> pointer<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>fill<span style="color: #66cc66;">-</span>rect<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function lib<span style="color: #66cc66;">-</span>sdl <span style="color: #ff0000;">&quot;SDL_FillRect&quot;</span> <span style="color: #66cc66;">&#40;</span>pointer pointer uint32<span style="color: #66cc66;">&#41;</span> int<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>flip<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function lib<span style="color: #66cc66;">-</span>sdl <span style="color: #ff0000;">&quot;SDL_Flip&quot;</span> <span style="color: #66cc66;">&#40;</span>pointer<span style="color: #66cc66;">&#41;</span> int<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>map<span style="color: #66cc66;">-</span>rgb<br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>function lib<span style="color: #66cc66;">-</span>sdl <span style="color: #ff0000;">&quot;SDL_MapRGB&quot;</span> <span style="color: #66cc66;">&#40;</span>pointer uint8 uint8 uint8<span style="color: #66cc66;">&#41;</span> uint32<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">;; Declare a type</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> SDL_Rect<span style="color: #66cc66;">*</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>type <span style="color: #ff0000;">&quot;SDL_Rect&quot;</span> 'sint16 'sint16 'uint16 'uint16<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span>sdl<span style="color: #66cc66;">-</span>init <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> sdl<span style="color: #66cc66;">-</span>surface <span style="color: #66cc66;">&#40;</span>sdl<span style="color: #66cc66;">-</span>set<span style="color: #66cc66;">-</span>video<span style="color: #66cc66;">-</span>mode <span style="color: #cc66cc;">640</span> <span style="color: #cc66cc;">480</span> <span style="color: #cc66cc;">16</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>sdl<span style="color: #66cc66;">-</span>fill<span style="color: #66cc66;">-</span>rect sdl<span style="color: #66cc66;">-</span>surface <span style="color: #66cc66;">&#40;</span>SDL_Rect<span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">640</span> <span style="color: #cc66cc;">480</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">32535</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>sdl<span style="color: #66cc66;">-</span>flip sdl<span style="color: #66cc66;">-</span>surface<span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span>sdl<span style="color: #66cc66;">-</span>quit<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>soload<span style="color: #66cc66;">-</span>kill<span style="color: #66cc66;">&#41;</span></div></div>
<p>Now that I've taken a break from this for a while, I can see a few areas it could be made more robust.  Next feature: an optional timeout period for SoLoad, so it can close gracefully even if the caller has crashed.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F&amp;title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F&amp;title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F&amp;title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F&amp;headline=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F&amp;title=A+Foreign+Function+Interface+for+Ikarus+Using+SoLoad&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F12%2F14%2Fa-foreign-function-interface-for-ikarus-using-soload%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2008/12/14/a-foreign-function-interface-for-ikarus-using-soload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Scheme Syntax-Rules Primer</title>
		<link>http://blog.willdonnelly.net/2008/09/04/a-scheme-syntax-rules-primer/</link>
		<comments>http://blog.willdonnelly.net/2008/09/04/a-scheme-syntax-rules-primer/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 02:34:48 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[scheme]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[macros]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=24</guid>
		<description><![CDATA[Scheme has a wonderfully powerful hygienic macro system [...]]]></description>
			<content:encoded><![CDATA[<p>Scheme has a wonderfully powerful hygienic macro system.  Unfortunately, explanations on how to use it are few and far between.  <a title="Revised^5 Report on the Algorithmic Languge Scheme" href="http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.3">R5RS </a>is utterly incomprehensible to anyone who doesn't already have a firm grounding in hygienic macro systems, and <a title="Teach Yourself Scheme in Fixnum Days" href="http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-10.html#node_chap_8">TYSiFD</a>'s section on macros dates from a time before syntax-rules and hygiene.</p>
<p>So this here is my attempt to share what I've learned over the past few days with regards to syntax-rules macros.  Bear in mind that at the time of writing this, I have known how to use syntax-rules since <strong>yesterday</strong>, but my knowledge seems to be complete enough to write a working module system, so here's my attempt to pass on what I've learned.</p>
<p>First things first.  You use define-syntax to create a top level binding, and let-syntax bears the same relationship to define-syntax as you'd expect.</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;; define-syntax is used to create</span><br />
<span style="color: #808080; font-style: italic;">;; &nbsp;a top-level binding of a macro</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> macro<br />
&nbsp; <span style="color: #66cc66;">&lt;</span>syntax transformer<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>That much is pretty clear from reading R5RS, now we need to figure out how to write the syntax transformer.  There are a few ways to do this, but the best way for beginners is to use syntax-rules, which avoids inadvertent variable capture and other such nasties automatically, and uses a rather elegant pattern matching language.</p>
<p>We'll start by trying to write a simple macro, <code class="codecolorer text default"><span class="text">while</span></code>. This will just be a standard looping construct that keeps executing over and over until its condition becomes false.  We want its usage to look something like this:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;; A simple while loop</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> x <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>while <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> x <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> x <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>print x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>So first, we need the <code class="codecolorer text default"><span class="text">define-syntax</span></code> form.</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> while<br />
&nbsp; <span style="color: #66cc66;">&lt;</span>syntax transformer<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Next, we need to write the syntax transformer itself.  This is where syntax-rules comes into play.  Syntax-rules uses pattern matching and text substitution to allow you to make some pretty advanced macros.  It looks like:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> while<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>keywords<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>pattern<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span>template<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>pattern<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span>template<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>I will explain keywords later.  For now, just leave that bit blank.  What we're interested in are those <code class="codecolorer scheme default"><span class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>pattern<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span>template<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span></span></code> pairs.  Each <code class="codecolorer scheme default"><span class="scheme"><span style="color: #66cc66;">&lt;</span>pattern<span style="color: #66cc66;">&gt;</span></span></code> is just that, a pattern of code that will be matched.  In our case, we want to match the pattern:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>while condition body ...<span style="color: #66cc66;">&#41;</span></div></div>
<p>Where the '...' signifies that <code class="codecolorer text default"><span class="text">body</span></code> may contain one or more forms.  Luckily for us, this is exactly the syntax that syntax-rules wants to see, so we can just plug it in, giving us:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> while<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>while condition body ...<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span>template<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>So far so good.  Now we just have to fill in the other half, with a suitable <code class="codecolorer text default"><span class="text">&lt;template&gt;</span></code></p>
<p>Before we can write the <code class="codecolorer text default"><span class="text">&lt;template&gt;</span></code>, though, we have to decide what we want the code to end up looking like.  Since this isn't a guide to scheme code in general, I'll just go ahead and say that we want the output to look like:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">; Thanks to Alex Shinn for pointing out a mistake</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> loop <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> condition<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; body ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>loop<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Got that?  Okay, now we've just got to put this in our syntax-rules macro as a template.  By another startling coincidence, this is exactly what the template code is expected to look like.  We just plug in that code, and our final result is:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> while<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>while condition body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> loop <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> condition<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;body ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>loop<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Just plug that into your scheme interpreter, and our <code class="codecolorer text default"><span class="text">while</span></code> loop from earlier should execute perfectly.</p>
<p>Now let's try to write something a little more complicated.  We want to write a <code class="codecolorer text default"><span class="text">for</span></code> loop similar to the one that Python has.  This should be a pretty easy task, since it's basically just syntactic sugar for scheme's <code class="codecolorer text default"><span class="text">map</span></code> function.</p>
<p>Our goal is to be able to write a piece of code taking the form:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>for <span style="color: #66cc66;">&lt;</span>element<span style="color: #66cc66;">&gt;</span> in <span style="color: #66cc66;">&lt;</span>list<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>body ...<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>And have it expand to:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">; Thanks to Alex Shinn for pointing out a mistake</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">for-each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>element<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>body ...<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span>list<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Our first try would probably look something like this:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> for<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>for element in <span style="color: #b1b100;">list</span> body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>This works, but there's one issue with it.  All of the following are valid and work exactly the same:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>for i in '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>print i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>for i fnord '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>print i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>for i some<span style="color: #66cc66;">-</span>other<span style="color: #66cc66;">-</span>keyword '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>print i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>This is not so much of a problem in the case of a for loop, but what if you wanted to add another rule later, so that</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>for '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> as i<br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>print i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>will also work?  The solution to this problem is in that <code class="codecolorer text default"><span class="text">&lt;keywords&gt;</span></code> argument that we glossed over earlier.  Change the keywords list to include 'in' (and, for good measure, 'as'), and it will allow those symbols, and only those symbols, in places where they are mentioned.  This change leaves us with:</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> for<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span>in as<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>for element in <span style="color: #b1b100;">list</span> body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>for <span style="color: #b1b100;">list</span> as element body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Or, for simplicity (thanks to Dan Prager for pointing this out)</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> for<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span>in as<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>for element in <span style="color: #b1b100;">list</span> body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>for <span style="color: #b1b100;">list</span> as element body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>for element in <span style="color: #b1b100;">list</span> body ...<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>And if we load this code into our scheme interpreter of choice, we should have two fully functional little bits of new syntax.</p>
<p>Hopefully this guide will help shed some light on the arcane subject that is the Scheme macro system, and hopefully I will never have to learn enough about syntax-case to write a tutorial on it.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F&amp;title=A+Scheme+Syntax-Rules+Primer" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F&amp;title=A+Scheme+Syntax-Rules+Primer" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F&amp;title=A+Scheme+Syntax-Rules+Primer" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F&amp;headline=A+Scheme+Syntax-Rules+Primer" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=A+Scheme+Syntax-Rules+Primer&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=A+Scheme+Syntax-Rules+Primer&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=A+Scheme+Syntax-Rules+Primer&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=A+Scheme+Syntax-Rules+Primer&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=A+Scheme+Syntax-Rules+Primer&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F&amp;title=A+Scheme+Syntax-Rules+Primer&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F09%2F04%2Fa-scheme-syntax-rules-primer%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2008/09/04/a-scheme-syntax-rules-primer/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>A Minimalistic Module System for Scheme</title>
		<link>http://blog.willdonnelly.net/2008/08/30/a-minimalistic-module-system-for-scheme/</link>
		<comments>http://blog.willdonnelly.net/2008/08/30/a-minimalistic-module-system-for-scheme/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 01:59:58 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[scheme]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=4</guid>
		<description><![CDATA[I like scheme.

I really, really like scheme.

Unfo [...]]]></description>
			<content:encoded><![CDATA[<p>I like <a title="scheme" href="http://en.wikipedia.org/wiki/Scheme_(programming_language)">scheme</a>.</p>
<p>I really, really like scheme.</p>
<p>Unfortunately, it seems like a lot of the time the only way to get worthwhile things done in scheme is to abandon the conceptual purity and the elegance, all of the things that make scheme as wonderful as it is.</p>
<p>I figure I'm as good a person as any to try and fix at least a little of that.</p>
<p>The first (second actually, but more about that in the next post) step toward that is some sort of cross-implementation module system.  As far as I know, the only such systems in existence so far are <a title="SLIB" href="http://people.csail.mit.edu/jaffer/SLIB.html">SLIB</a> and <a title="Snowfort" href="http://snow.iro.umontreal.ca/">Snowfort</a>.  While both of these are wonderful systems, they overshoot the mark, in my opinion.  SLIB aims to be a complete all-singing all-dancing library system, and Snowfort integrates all kinds of package management with the simple act of breaking a program up into modules.</p>
<p>Well, that's the beauty of lisp, isn't it?  If you need something, you can just code it yourself.</p>
<p>So I did.  The preliminary result is only 19 lines of code, 6 of which are simply a function to build an alist from a key list and a value list.  It can also double as a simple object system if you want to use it that way.</p>
<p>Its usage is simple.  There are two macros, provide and module. Provide is basically the same as module, but anonymous, so it needs no documentation other than to say that you omit the name.</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;; simple-module-example.scm</span><br />
<span style="color: #808080; font-style: italic;">;;; Show off the usage of simple-module.scm</span><br />
<span style="color: #808080; font-style: italic;">;;; By Will Donnelly</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; This program is free software. It comes without any warranty, to</span><br />
<span style="color: #808080; font-style: italic;">;; the extent permitted by applicable law. You can redistribute it</span><br />
<span style="color: #808080; font-style: italic;">;; and/or modify it under the terms of the Do What The Fuck You Want</span><br />
<span style="color: #808080; font-style: italic;">;; To Public License, Version 2, as published by Sam Hocevar. See</span><br />
<span style="color: #808080; font-style: italic;">;; http://sam.zoy.org/wtfpl/COPYING for more details.</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">load</span> <span style="color: #ff0000;">&quot;simple-module.scm&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; (module &lt;name&gt; (&lt;exports&gt; ...) &lt;body&gt; ...)</span><br />
<span style="color: #66cc66;">&#40;</span>module mod<span style="color: #66cc66;">-</span>name <span style="color: #66cc66;">&#40;</span>foo incr<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> foo <span style="color: #cc66cc;">37</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> i <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; i cannot be accessed directly</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>incr<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> i <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> i <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#40;</span>mod<span style="color: #66cc66;">-</span>name 'foo<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; 37</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>mod<span style="color: #66cc66;">-</span>name 'incr<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; 11</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>mod<span style="color: #66cc66;">-</span>name 'incr<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; 12</span><br />
<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>mod<span style="color: #66cc66;">-</span>name 'incr<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; =&gt; 13</span></div></div>
<p>That's all you have to do to use it.  The code inside the module system is about as simple as that too.</p>
<div class="codecolorer-container scheme default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;; simple-module.scm</span><br />
<span style="color: #808080; font-style: italic;">;;; A minimalistic module system for scheme</span><br />
<span style="color: #808080; font-style: italic;">;;; By Will Donnelly</span><br />
<br />
<span style="color: #808080; font-style: italic;">;; This program is free software. It comes without any warranty, to</span><br />
<span style="color: #808080; font-style: italic;">;; the extent permitted by applicable law. You can redistribute it</span><br />
<span style="color: #808080; font-style: italic;">;; and/or modify it under the terms of the Do What The Fuck You Want</span><br />
<span style="color: #808080; font-style: italic;">;; To Public License, Version 2, as published by Sam Hocevar. See</span><br />
<span style="color: #808080; font-style: italic;">;; http://sam.zoy.org/wtfpl/COPYING for more details.</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>alist names values<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> names<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> names<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> names<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>alist <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> names<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> provide<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ <span style="color: #66cc66;">&#40;</span>exports ...<span style="color: #66cc66;">&#41;</span> body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; body ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> export<span style="color: #66cc66;">-</span>alist<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>alist '<span style="color: #66cc66;">&#40;</span>exports ...<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> exports ...<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>symbol<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assoc</span> symbol export<span style="color: #66cc66;">-</span>alist<span style="color: #66cc66;">&#41;</span> '<span style="color: #66cc66;">&#40;</span>#f . #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define-syntax</span> module<br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">syntax-rules</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ name <span style="color: #66cc66;">&#40;</span>exports ...<span style="color: #66cc66;">&#41;</span> body ...<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> name <span style="color: #66cc66;">&#40;</span>provide <span style="color: #66cc66;">&#40;</span>exports ...<span style="color: #66cc66;">&#41;</span> body ...<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Just load that code into your scheme interpreter, and you have a simple module system.  That's all there is to it.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F&amp;title=A+Minimalistic+Module+System+for+Scheme" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F&amp;title=A+Minimalistic+Module+System+for+Scheme" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F&amp;title=A+Minimalistic+Module+System+for+Scheme" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F&amp;headline=A+Minimalistic+Module+System+for+Scheme" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=A+Minimalistic+Module+System+for+Scheme&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=A+Minimalistic+Module+System+for+Scheme&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=A+Minimalistic+Module+System+for+Scheme&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=A+Minimalistic+Module+System+for+Scheme&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=A+Minimalistic+Module+System+for+Scheme&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F&amp;title=A+Minimalistic+Module+System+for+Scheme&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2008%2F08%2F30%2Fa-minimalistic-module-system-for-scheme%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2008/08/30/a-minimalistic-module-system-for-scheme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
