<?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>Artisan Coder &#187; Lisp</title>
	<atom:link href="http://www.artisancoder.com/category/programming/lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artisancoder.com</link>
	<description>Software development as a craft</description>
	<lastBuildDate>Thu, 09 Sep 2010 14:42:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Praising macros</title>
		<link>http://www.artisancoder.com/2010/06/praising-macros/</link>
		<comments>http://www.artisancoder.com/2010/06/praising-macros/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 21:37:20 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://www.artisancoder.com/?p=182</guid>
		<description><![CDATA[Macros are an indispensable programming feature. While procedures (functions, methods, messages etc.) let developers reuse common computation patterns, macros allow the abstraction of common syntactic constructions. These constructions can be as simple as a new control operator, or can be full domain-specific languages. For instance, there is no when operator in Scheme, but a lot [...]]]></description>
			<content:encoded><![CDATA[<p>Macros are an indispensable programming feature. While procedures (functions, methods, messages etc.) let developers reuse common computation patterns, macros allow the abstraction of common syntactic constructions. These constructions can be as simple as a new control operator, or can be full <a href="http://en.wikipedia.org/wiki/Domain-specific_language" title="Domain-specific language">domain-specific languages</a>. For instance, there is no <tt>when</tt> operator in Scheme, but a lot of people like it. It simply tests a condition and execute a block of code if the former evaluates to true:</p>

<div class="wp_codebox"><table><tr id="p1823"><td class="code" id="p182code3"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span>launch<span style="color: #66cc66;">-</span>authorised? president<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>fuel<span style="color: #66cc66;">-</span>missile icbm<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>open<span style="color: #66cc66;">-</span>hatch silo<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>launch<span style="color: #66cc66;">-</span>missile icbm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Another example of control operator is the very useful <a href="http://www.artisancoder.com/2008/12/equivalent-of-and-let/" title="Equivalent of and-let*?"><tt>and-let*</tt></a> macro, semi-standardised in <a href="http://srfi.schemers.org/srfi-2/" title="SRFI 2: AND-LET*: an AND with local bindings, a guarded LET* special form">SRFI-2</a>, tests several expressions in sequence, aborting the computation if any of them evaluates to false, optionally binding variables to the expressions&#8217;s resulting values in nested scopes otherwise. If none of the expressions evaluate to false, the body is executed in the resulting lexical environment. Those familiar with Haskell may find it somewhat similar to the <tt>Maybe</tt> monad.</p>
<p>Actually several of Scheme&#8217;s own standard control operators are macros, implemented almost exactly as user-defined macros. A named <tt>let</tt> can be easily rewritten as a <tt>letrec</tt> operator:</p>

<div class="wp_codebox"><table><tr id="p1824"><td class="code" id="p182code4"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; a named let expression</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> collect <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>seq <span style="color: #66cc66;">&#40;</span>produce<span style="color: #66cc66;">-</span>list<span style="color: #66cc66;">-</span>of<span style="color: #66cc66;">-</span>numbers<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span>even '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span>odd '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> seq<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> even odd<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>num <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> seq<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">even?</span> num<span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>collect <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> seq<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> num even<span style="color: #66cc66;">&#41;</span> odd<span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>collect <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> seq<span style="color: #66cc66;">&#41;</span> even <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> num odd<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;
<span style="color: #808080; font-style: italic;">;; becomes a letrec expression</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">letrec</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>collect <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>seq even odd<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> seq<span style="color: #66cc66;">&#41;</span>
                        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> even odd<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>num <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> seq<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                         <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">even?</span> num<span style="color: #66cc66;">&#41;</span>
                             <span style="color: #66cc66;">&#40;</span>collect <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> seq<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> num even<span style="color: #66cc66;">&#41;</span> odd<span style="color: #66cc66;">&#41;</span>
                             <span style="color: #66cc66;">&#40;</span>collect <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> seq<span style="color: #66cc66;">&#41;</span> even <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> num odd<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;">&#40;</span>collect <span style="color: #66cc66;">&#40;</span>produce<span style="color: #66cc66;">-</span>list<span style="color: #66cc66;">-</span>of<span style="color: #66cc66;">-</span>numbers<span style="color: #66cc66;">&#41;</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><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Macros are of course not limited to adding new control operators to a language. One can design his own little language for solving specific problems, like <a href="http://www.artisancoder.com/2008/04/dsls-are-cool/" title="DSLs are cool">stocks trading</a>. Or a data modelling language, a graphics drawing language etc. A language for object-oriented programming such as <a href="http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/Meroon.html" title="Meroon: an Object System in Scheme">Meroon</a> can be seamlessly embedded within Scheme. Paul Graham&#8217;s <a href="http://www.paulgraham.com/onlisp.html" title="On Lisp">On Lisp</a> book on advanced Common Lisp programming has several chapters devoted to macros. In short, the developer becomes almost as powerful as the language designer, and such distinction is blurred. Armed with such power, the developer becomes much more productive and, therefore, happy.</p>
<p>Unfortunately not many programming languages provide good macro facilities. The C preprocessor, for instance, only does textual replacement and is no aware of expressions. Granted, the syntax of the programming languages of the Lisp family is very simple and uniform, making better macros possible. Nevertheless other languages like <a href="http://www.haskell.org/haskellwiki/Template_Haskell" title="Template Haskell">Haskell</a> and <a href="http://brion.inria.fr/gallium/index.php/Camlp4" title="Camlp4">OCaml</a> with more complex syntax also provide such facilities.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2010/06/praising-macros/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scheme hits the App Store</title>
		<link>http://www.artisancoder.com/2009/10/scheme-hits-the-app-store/</link>
		<comments>http://www.artisancoder.com/2009/10/scheme-hits-the-app-store/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 19:32:47 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[othello]]></category>
		<category><![CDATA[reversi]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=123</guid>
		<description><![CDATA[I believe I have got the first Scheme application past Apple review into the iTunes App Store. It is yet another Reversi clone, called Reverso. It is a combination of 90% Scheme and 10% Objective-C, written with Gambit-C Scheme. James Long has already shown how to compile Gambit-C for the iPhone, and I started from [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.dunasystems.com.br/reverso/images/revlogo.png" alt="Reverso logo" style="float:left;padding:20px;" /></p>
<p>I believe I have got the first Scheme application past Apple review into the iTunes App Store. It is yet another <a href="http://en.wikipedia.org/wiki/Reversi" title="Reversi">Reversi</a> clone, called <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=334979538&#038;mt=8" title="Reverso">Reverso</a>. It is a combination of 90% Scheme and 10% Objective-C, written with <a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page" title="Gambit-C">Gambit-C Scheme</a>. James Long has already <a href="http://jlongster.com/blog/2009/06/17/write-apps-iphone-scheme/" title="Writing apps for the iPhone in Scheme">shown how to compile Gambit-C for the iPhone</a>, and I started from there. My Scheme code is compiled to C by Gambit and later by GCC to produce native ARM code, bundled in a static library, which is ok with the iPhone SDK license agreement. The Objective-C then calls the library as a pure C library. The Scheme code deals with position evaluation, alpha-beta pruning, transposition tables, move legality, different strategies and so on. The Objective-C code deals with sound, animations, GUI, user preferences, basically everything that calls the iPhone OS API. Reversi was chosen because I like strategy games and it is much more algorithmic than artistic, and I am no artist.</p>
<p>The performance of the code is excellent. I used some Gambit-specific declarations, only fixnum arithmetic, pre-allocated a large heap, and called the garbage-collector every time the user needed to think. The search is not memory intensive, but the transposition tables are. I did not write a specific hash function but relied on Gambit-C&#8217;s table type. The boards used during search were retrieved from a pool (the newest Gambit-C has made <tt>subu8vector-move!</tt> a public API), so they did not put pressure on the garbage-collector. In the end it was a very successful experiment. Developing with Scheme is orders of magnitude more productive than with most other languages. Gambit-C is also one of the best Scheme compilers out there, and made my job a lot easier.</p>
<p><strong>Update</strong>: There was a bug in the application that caused it to play poorly. The weak AI was not Gambit&#8217;s or Scheme&#8217;s fault, but mine. I already sent an updated version to Apple that will play much better. Besides fixing the bug, I am now using Zobrist&#8217;s hashing instead of Gambit&#8217;s own hash function, that performs poorly for game positions. It is still written in Scheme, though. Now I am waiting for the approval of the update, and to hear further feedback from my users. <img src='http://www.artisancoder.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2009/10/scheme-hits-the-app-store/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Equivalent of and-let*?</title>
		<link>http://www.artisancoder.com/2008/12/equivalent-of-and-let/</link>
		<comments>http://www.artisancoder.com/2008/12/equivalent-of-and-let/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:33:47 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[srfi-2]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=64</guid>
		<description><![CDATA[By this point I believe it&#8217;s clear that I am a big fan of Scheme. Lately I have seen a sharp rise of interest in Ruby in some virtual places I attend (#lisp-br, twitter, IM with coworkers etc.). I am sure Ruby is a fine language, even in spite of several complaints I hear from [...]]]></description>
			<content:encoded><![CDATA[<p>By this point I believe it&#8217;s clear that I am a big fan of <a href="http://www.schemers.org/" title="An improper list of Scheme resources">Scheme</a>. Lately I have seen a sharp rise of interest in Ruby in some virtual places I attend (#lisp-br, twitter, IM with coworkers etc.). I am sure Ruby is a fine language, even in spite of several complaints I hear from some of its users. After all, it has symbols, metaprogramming, blocks (a sort of closures), <em>lambdas</em> and more! I&#8217;d really take the time to learn it, if it wasn&#8217;t for <a href="http://www.paulgraham.com/quotes.html" title="Lisp Quotes">Matz himself</a>:</p>
<blockquote>
<p>Some may say Ruby is a bad rip-off of Lisp or Smalltalk, and I admit that. But it is nicer to ordinary people.</p>
</blockquote>
<p>Now <em>that</em> is a demotivator. But Ruby must be evolving, and that quote may be outdated. So I have thought of a question to the Ruby-lovers, that may help me make up my mind to take the time to learn it. One of the best Scheme macros is, in my opinion, <tt>and-let*</tt>, from the <a href="http://srfi.schemers.org/srfi-2/srfi-2.html" title="AND-LET*: an AND with local bindings, a guarded LET* special form">SRFI-2</a>. How would one write the following in Ruby, a procedure that I wrote a couple of nights ago?</p>

<div class="wp_codebox"><table><tr id="p646"><td class="code" id="p64code6"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; Tries to get session from current request</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>session request<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>and<span style="color: #66cc66;">-</span><span style="color: #b1b100;">let*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>cookies <span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">-</span>cookies request<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span>p <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assoc</span> <span style="color: #ff0000;">&quot;session_id&quot;</span> cookies<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span>sid<span style="color: #66cc66;">-</span>str <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> p<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span>sid <span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">-&gt;</span>number sid<span style="color: #66cc66;">-</span>str<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">integer?</span> sid<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exact?</span> sid<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span>sp <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assq</span> sid <span style="color: #66cc66;">*</span>sessions<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> sp<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>In the <tt>and-let*</tt> macro, the clauses are evaluated and the variables are bound sequentially, creating new scopes for the next expressions. If any of the forms evaluates to <tt>#f</tt> (false in Scheme), the computation is aborted, no other expressions are evaluated, and the whole form evaluates to <tt>#f</tt>. How would I write this in concise Ruby?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/12/equivalent-of-and-let/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Lisp in Latinoware 2008</title>
		<link>http://www.artisancoder.com/2008/10/lisp-in-latinoware-2008/</link>
		<comments>http://www.artisancoder.com/2008/10/lisp-in-latinoware-2008/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 13:31:21 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[latin america]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=54</guid>
		<description><![CDATA[There will be presentations about Lisp in the V Latin America Conference on Free Software, via call-with-hopeless-continuation.]]></description>
			<content:encoded><![CDATA[<p>There will be presentations about Lisp in the <a href="http://2008.latinoware.org/" title="Latinoware 2008">V Latin America Conference on Free Software</a>, via <a href="http://call-with-hopeless-continuation.blogspot.com/2008/10/lisp-na-latinoware-2008.html" title="call/hc">call-with-hopeless-continuation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/10/lisp-in-latinoware-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bibliography of Programming Languages Implementation</title>
		<link>http://www.artisancoder.com/2008/07/bibliography-of-programming-languages-implementation/</link>
		<comments>http://www.artisancoder.com/2008/07/bibliography-of-programming-languages-implementation/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 14:54:56 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=14</guid>
		<description><![CDATA[Doing some research about compilers, interpreters and virtual machines, I have gathered some bibliography from several resources. Here it is, in no particular order: Essentials of Programming Languages, by Daniel P. Friedman, Mitchell Wand and Christopher T. Haynes Programming Language Pragmatics, by Michael L. Scott Smalltalk-80: The Language and Its Implementation, by Adele Goldberg and [...]]]></description>
			<content:encoded><![CDATA[<p>Doing some research about compilers, interpreters and virtual machines, I have gathered some bibliography from several resources. Here it is, in no particular order:</p>
<ul>
<li><a href="http://www.cs.indiana.edu/eopl/" title="Essentials of Programming Languages">Essentials of Programming Languages</a>, by <a href="http://www.cs.indiana.edu/hyplan/dfried.html" title="Daniel P. Friedman">Daniel P. Friedman</a>, <a href="http://www.ccs.neu.edu/home/wand" title="Mitchell Wand">Mitchell Wand</a> and <a href="http://www.cs.indiana.edu/hyplan/chaynes.html" title="Christopher T. Haynes">Christopher T. Haynes</a></li>
<li><a href="http://www.cs.rochester.edu/~scott/pragmatics/" title="Programming Language Pragmatics">Programming Language Pragmatics</a>, by Michael L. Scott</li>
<li><a href="http://users.ipa.net/~dwighth/smalltalk/bluebook/bluebook_imp_toc.html" title="Smalltalk-80: The Language and Its Implementation">Smalltalk-80: The Language and Its Implementation</a>, by Adele Goldberg and David Robson</li>
<li><a href="http://portal.acm.org/citation.cfm?coll=GUIDE&#038;dl=GUIDE&#038;id=525376" title="Writing Compilers and Interpreters: An Applied Approach Using C++">Writing Compilers and Interpreters: An Applied Approach Using C++</a>, by <a href="http://portal.acm.org/author_page.cfm?id=81100175907&#038;coll=GUIDE&#038;dl=GUIDE&#038;trk=0&#038;CFID=35005474&#038;CFTOKEN=42269298" title="Ronald L. Mak">Ronald L. Mak</a></li>
<li><a href="http://www.cs.princeton.edu/~appel/modern/ml/" title="Modern Compiler Implementation in ML">Modern Compiler Implementation in ML</a>, by <a href="http://www.cs.princeton.edu/~appel" title="Andrew W. Appel">Andrew W. Appel</a></li>
<li><a href="http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiSP.html" title="Lisp in Small Pieces">Lisp in Small Pieces</a>, by <a href="http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/Queinnec.html" title="Christian Queinnec">Christian Queinnec</a></li>
<li><a href="http://lambda-the-ultimate.org/node/1752" title="An Incremental Approach to Compiler Construction">An Incremental Approach to Compiler Construction</a>, by Abdulaziz Ghuloum</li>
<li><a href="http://compilers.iecc.com/crenshaw/" title="Let's Build a Compiler">Let&#8217;s Build a Compiler</a>, by Jack Crenshaw</li>
<li><a href="http://mitpress.mit.edu/sicp/" title="Structure and Interpretation of Computer Programs">Structure and Interpretation of Computer Programs</a>, by Harold Abelson and Gerald Jay Sussman, with Julie Sussman</li>
<li><a href="http://www.elsevier.com/wps/find/bookdescription.cws_home/677874/description#description" title="Advanced Compiler Design and Implementation">Advanced Compiler Design and Implementation</a>, by Steven Muchnick</li>
<li><a href="http://www.iro.umontreal.ca/~boucherd/mslug/meetings/20041020/minutes-en.html" title="The 90 Minute Scheme to C compiler">The 90 Minute Scheme to C compiler</a>, by Marc Feeley</li>
<li><a href="http://dragonbook.stanford.edu/" title="Compilers: Principles, Techniques, and Tools">Compilers: Principles, Techniques, and Tools</a>, by Aho, Lam, Sethi and Ulman (the &#8220;Dragon Book&#8221;)</li>
<li><a href="http://www.elsevierdirect.com/product.jsp?isbn=155860698x&#038;" title="Engineering a Compiler">Engineering a Compiler</a>, by Keith Cooper and Linda Torczon</li>
<li><a href="http://www.reddit.com/info/63hth/comments/c02pxbp" title="Mike Pall's guide to the Lua source code">Mike Pall&#8217;s guide to the Lua source code</a></li>
<li><a href="http://liinwww.ira.uka.de/csbib/Compiler/Inst.Computersprachen.TUWien?query=Ertl&#038;partial=off&#038;case=on&#038;maxnum=200&#038;sort=year" title="Anton Ertl's papers">Anton Ertl&#8217;s papers</a></li>
<li><a href="https://www.cs.tcd.ie/David.Gregg/pubs.html" title="David Gregg's papers">David Gregg&#8217;s papers</a></li>
<li><a href="http://www.ics.uci.edu/%7Efranz/Site/publications.html" title="Michael Franz's papers">Michael Franz&#8217;s papers</a></li>
<li><a href="http://www.cs.kent.ac.uk/people/staff/rej/gcbook/gcbook.html" title="Garbage Collection: Algorithms for Automatic Dynamic Memory Management">Garbage Collection: Algorithms for Automatic Dynamic Memory Management</a>, by <a href="http://www.cs.kent.ac.uk/people/staff/rej/" title="Richard Jones">Richard Jones</a> and Rafael D Lins</li>
<li><a href="http://www.norvig.com/paip.html" title="Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp">Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp</a>, by <a href="http://www.norvig.com/index.html" title="Peter Norvig">Peter Norvig</a></li>
<li><a href="http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-453.pdf" title="The Art of the Interpreter of, the Modularity Complex (Parts Zero, One, and Two)">The Art of the Interpreter of, the Modularity Complex (Parts Zero, One, and Two)</a>, by Guy Lewis Steele, Jr. and Gerald Jay Sussman</li>
<li><a href="http://library.readscheme.org/page8.html" title="Compiler section on readscheme.org">Compiler section on readscheme.org</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/07/bibliography-of-programming-languages-implementation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Kent Pitman, again</title>
		<link>http://www.artisancoder.com/2008/06/kent-pitman-again/</link>
		<comments>http://www.artisancoder.com/2008/06/kent-pitman-again/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 11:40:44 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[quote]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=13</guid>
		<description><![CDATA[And anyway, the subject line presupposes that Lisp has not caught on. This is like saying that astrophysics or calculus or brain surgery has not caught on because in relative numbers, there might be more people doing other things. The success of Lisp is not measured in the number of people using it, it&#8217;s measured [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://groups.google.com/group/comp.lang.lisp/msg/5dcbcadf292ce34a?hl=en"><p>And anyway, the subject line presupposes that Lisp has not caught on. This is like saying that astrophysics or calculus or brain surgery has not caught on because in relative numbers, there might be more people doing other things.  The success of Lisp is not measured in the number of people using it, it&#8217;s measured in the utility to those people who do use it.  Turning it into C (or C++ or C#) to make it more popular would not be success.  In the world&#8217;s menu of computer language options, we don&#8217;t need them all to be Taco Bell.</p></blockquote>
<div style="text-align:right;font-size:8pt;">&mdash;&nbsp;<cite><a href="http://groups.google.com/group/comp.lang.lisp/msg/5dcbcadf292ce34a?hl=en">Kent Pitman</a></cite>.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/06/kent-pitman-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Toy Scheme interpreter in Lua</title>
		<link>http://www.artisancoder.com/2008/06/toy-scheme-interpreter-in-lua/</link>
		<comments>http://www.artisancoder.com/2008/06/toy-scheme-interpreter-in-lua/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 22:20:37 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=11</guid>
		<description><![CDATA[As part of my Lisp studies, I have implemented a toy Scheme interpreter in roughly 1000 lines of Lua. It is here. It supports tail-call optimisation, lexical scope for closures, and first-class continuations via call/cc. I have departed from the traditional approach of implementing a Scheme interpreter in Scheme itself because I wanted to avoid [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my Lisp studies, I have implemented a toy Scheme interpreter in roughly 1000 lines of <a href="http://www.lua.org/" title="Lua">Lua</a>. It is <a href="http://www.artisancoder.com/files/" title="artisancoder.com files">here</a>. It supports <a href="http://en.wikipedia.org/wiki/Tail_recursion">tail-call optimisation</a>, lexical scope for closures, and first-class <a href="http://en.wikipedia.org/wiki/Continuation">continuations</a> via <tt>call/cc</tt>.</p>
<p>I have departed from the traditional approach of implementing a Scheme interpreter in Scheme itself because I wanted to avoid possible confusions between the defined language and the defining language. This has made a lot of the concepts clearer. The evaluator is written in <a href="http://en.wikipedia.org/wiki/Continuation_passing_style">continuation-passing style</a>, which is easily done in Lua because the latter has tail-call optimisations. This way it is easier to reify continuations to first-class values.</p>
<p>I have also added a few primitives to allow me to run some examples, as the factorial and fibonacci functions. More primitives can be easily added if desired.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/06/toy-scheme-interpreter-in-lua/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Does the World need another Scheme system?</title>
		<link>http://www.artisancoder.com/2008/05/does-the-world-need-another-scheme-system/</link>
		<comments>http://www.artisancoder.com/2008/05/does-the-world-need-another-scheme-system/#comments</comments>
		<pubDate>Wed, 21 May 2008 19:27:32 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=9</guid>
		<description><![CDATA[I am currently reading the third chapter of Lisp in Small Pieces. It is really a wonderful book. By teaching how to implement Lisp, it teaches a lot about using the language too. Moreover, reading it sometimes I feel the urge that almost every Schemer has at one time or another felt: The urge to [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently reading the third chapter of <a href="http://www.amazon.com/gp/product/0521545668/ref=s9qpick_c2_at3-2871_p?pf_rd_m=ATVPDKIKX0DER&#038;pf_rd_s=center-&#038;pf_rd_r=0E22QSHYB0WW14SABE40&#038;pf_rd_t=101&#038;pf_rd_p=278247301&#038;pf_rd_i=507846" title="Lisp in Small Pieces">Lisp in Small Pieces</a>. It is really a wonderful book. By teaching how to implement Lisp, it teaches a lot about using the language too. Moreover, reading it sometimes I feel the urge that almost every Schemer has at one time or another felt: The urge to write his own Scheme system.</p>
<p>Ok, I know the World is already sick of Schemes, it only takes a look at this <a href="http://community.schemewiki.org/?scheme-faq-standards#implementations" title="What Scheme implementations are there?">list</a> to know why. But I still think I have to do it, if only for my personal learning. There is no need to bore the World to death with another half-done Scheme. Sometimes I think about features that could make my Scheme useful, though. They are probably never going to be implemented, but here they are:<br />
<h3>Full R5RS compliance</h3>
<p>The R5RS is a piece of art (R6RS, on the other hand, is a stain, a mess). Of course it does not describe a terribly useful system, but it beautifully describes the <strong>core</strong> of one. Everything else can then come from there. For more compliance with other systems, the SRFIs can be used as the basis for a standard library.</p>
<h3>Bytecode virtual machine</h3>
<p>Although Scheme is a dynamic language, there is a <em>lot</em> that can be known about the program before executing it. Lexical variables, never assigned variables, closure and continuation creation etc. This can be processed at compile time, allowing for a simple and fast virtual machine. Interpreting the source code directly is easier but very inefficient for any serious system.<br />
<h3>Incremental garbage collection</h3>
<p>Stop-and-go garbage collectors are easier to implement, but in some applications the pause is inacceptable. For applications like interactive games, the smooth user experience only can be achieved by an incremental garbage collector. It would be nice if it was a moving collector too, to avoid too much fragmentation of the heap (some naive C programmers think the use of <tt>malloc</tt> and <tt>free</tt> can beat a garbage collector in any circustances, until they are hit in the face by heap fragmentation. There is a reason the Apache web server uses memory pools). If I remember correctly the CLR garbage collector is very good and compacts the memory without the use of from- and to-spaces, which is cool, because uses less heap memory. Hmm, while I am dreaming about my ideal garbage collector, make it concurrent too (see below).</p>
<h3>Concurrency</h3>
<p>These days the hot topic is concurrency. New personal computers with two and four cores sell more and more every day. The programming languages/environments that makes easy for the programmer to use these new cores are going to be big. <a href="http://www.erlang.org/" title="Erlang">Erlang</a> is the hottest thing right now in this regard, although <a href="http://www.haskell.org/" title="Haskell">Haskell</a> is a strong candidate too. In the mainstream Java has a concurrent VM, but Java uses the old lock/unlock paradigm of other mainstream languages, <a href="http://clojure.sourceforge.net/" title="Clojure">Clojure</a> is the new language on top of the JVM that leverage that power for the programmer. But although this is all so hot, the only thing that seems to be happening to Scheme is <a href="http://toute.ca/" title="Termite">Termite</a>, which as far as I know can only use green threads. My hypotetical Scheme would have a concurrent VM, <a href="http://www.artisancoder.com/2008/05/concurrent-scheme/" title="Concurrent Scheme">some Scheme compilation techniques</a> already give a start in that direction. There would be maybe a <tt>spawn-continuation</tt> form that would take a continuation captured with <tt>call/cc</tt> and resume it in parallel with the current one, in a M:N model (M continuations spread on N OS threads).</p>
<h3>Just-in-time compilation</h3>
<p>Well, once dreaming, why not go all the way? One of the nice things about Scheme is the bottom-up, incremental development. Developing at the REPL gives instant feedback and ease debugging. What if it could give the speed of compiled-to-CPU languages as well? Another advantage is hot-swapping code in a running application. This can&#8217;t be done with Chicken or Gambit, which are fast, but Scheme-to-C compilers. Larceny, Chez and Ikarus can do this. By using a bytecode VM, the system is portable to wherever there is a C compiler, and by adding JIT support for some architectures it can be made fast too.</p>
<h3>Escape continuations</h3>
<p>Full, first-class continuations with indefinite extent are a powerful and mind-bending feature, but unfortunately, are usually hard to implement and causes pauses when invoked. Besides them, my hypotetical Scheme would have escape continuations. Instead of completely overwriting the execution stack, they simply unwind it until some recorded point, which can be made very fast. Exceptions would them be implemented as escape continuations rather than full ones.</p>
<h3>Easy FFI</h3>
<p>I am a long-time <a href="http://www.lua.org/" title="Lua">Lua</a> user, and it is amazing how they could get the C API so good. Not only it is very easy to add new C/C++ libraries to Lua, it is trivial to embed the Lua interpreter itself in a legacy application, or an application that needs to be mostly in C/C++, such as games. As Scheme, unfortunately, is not one of the World&#8217;s favorite languages, the capacity to talk to the outside World is fundamental. And by being embeddable (which is the goal of Guile, but it sucks for Windows), it would be easier to take Scheme to another domains where it is not so popular today.</p>
<p>Well, I guess this is it. Thinking about it, there seems to be no Scheme system today with all these features. Will I have the skills to write something like this after LiSP? I doubt it, only the garbage collector would take me ages. But it would be nice if such thing existed&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/05/does-the-world-need-another-scheme-system/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Concurrent Scheme</title>
		<link>http://www.artisancoder.com/2008/05/concurrent-scheme/</link>
		<comments>http://www.artisancoder.com/2008/05/concurrent-scheme/#comments</comments>
		<pubDate>Thu, 08 May 2008 20:28:17 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=8</guid>
		<description><![CDATA[While I wait for my 1-hour mobile phone software compilation to finish I decided to drop a quick post about something that has been on my mind lately. In his nice PhD thesis (that I had to read five times to finally understand it), Dybvig (the implementor of Chez Scheme) shows a compiler that rewards [...]]]></description>
			<content:encoded><![CDATA[<p>While I wait for my 1-hour mobile phone software compilation to finish I decided to drop a quick post about something that has been on my mind lately. In his nice <a href="http://www.cs.indiana.edu/~dyb/papers/3imp.pdf" title="Three Implementation Models for Scheme">PhD thesis</a> (that I had to read five times to finally understand it), Dybvig (the implementor of <a href="http://www.scheme.com/" title="Chez Scheme">Chez Scheme</a>) shows a compiler that rewards the pure functional use of the Scheme language. The compiler scans for free variables in <tt>lambda</tt> forms and, when creating the respective closures, put the <em>values</em> of the variables directly in the closure activation frame. The references to the free variables in the closure are then changed to references to the stack locations. Accessing the variables is then pretty fast. Besides, when a first-class continuation is created, it suffices to blindingly copy the execution stack because all closures will carry their free variables with them. Assignment is then added at a later section of the thesis. To support it the compiler scans the code for <tt>set!</tt> forms, gathering the variables that are ever assigned, and compiling them to indirections to heap memory. When a continuation is created the indirection box is copied, not the actual variable, which lives in the heap. So access to assigned variables is much slower.</p>
<p>Although the focus of Dybvig&#8217;s thesis is not on concurrency, I cannot help but think that his compiler could work very well for this too with just minor modifications. If variables (local or free) are never assigned, they could be replaced by their values and several different threads with different execution stacks could run in parallel. If a variable is assigned, the access to its indirection box could be protected by a mutex or similar synchronisation primitive. Of course this would make access to assigned variables even slower, because even variables ever used by only one single thread would need mutex lock/unlock operations. On the other hand, isn&#8217;t assignment discouraged in Scheme? The overall execution time would compensate for this, if the rest of the program was parallelised.</p>
<p>But surely I am missing something, because no one ever seems to think Scheme can be a contender in the massive-parallelised future. What bugs me is that I don&#8217;t know what it is that I am not taking in consideration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/05/concurrent-scheme/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>DSLs are cool</title>
		<link>http://www.artisancoder.com/2008/04/dsls-are-cool/</link>
		<comments>http://www.artisancoder.com/2008/04/dsls-are-cool/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 18:54:58 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=4</guid>
		<description><![CDATA[One of the most promoted features of the Lisp dialects is how easy it is to create Domain Specific Languages with them. It is said that a Lisp programmer creates a language for the domain of his problem and then solves the problem as a particular case. That is why a lone developer or a [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most promoted features of the Lisp dialects is how easy it is to create <a href="http://en.wikipedia.org/wiki/Domain Specific Languages">Domain Specific Languages</a> with them. It is said that a Lisp programmer creates a language for the domain of his problem and then solves the problem as a particular case. That is why a lone developer or a small team can have so much power, because they are quickly dealing with a language customised for them. In my case, one of the domains of my problems is the stock market.</p>
<p>I am writing a very simple application in Scheme, with <a title="Gambit-C Scheme" href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page">Gambit-C Scheme</a>, for helping me trade stocks (nothing fancy, I am still an amateur). This application is going to have a comprehensive set of <a href="http://en.wikipedia.org/wiki/Technical analysis">technical indicators</a> which are calculated based on opening, closing, maximum and minimum stock prices as well as the volume traded, number of operations, number of stocks traded etc. Clearly these indicators must be first-class citizens of this small financial world. Once added to the system, I must know how many I have, what is the name the user should see for each of them and the parameters they take. Besides, its syntax must allow users of the system to add indicators of their own without knowing the inner details of the system.</p>
<p>To accommodate those needs I have come up with a little language for my indicators. For instance, these are the Volume and Force Index indicators:</p>

<div class="wp_codebox"><table><tr id="p410"><td class="code" id="p4code10"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>indicator volume <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Volume&quot;</span>
  <span style="color: #66cc66;">&#40;</span>volume x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>indicator force<span style="color: #66cc66;">-</span>index <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Force Index&quot;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>closing <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> <span style="color: #66cc66;">&#40;</span>closing x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>volume x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>The indicator syntax allows me to give the indicator a user-friendly name, and to automatically add it to my indicator list. But there is something more subtle and interesting about them: the <em>helper</em> procedures. The procedures <tt>closing</tt> and <tt>volume</tt> are examples of procedures available to indicator writers. They cannot be lexically scoped, because they depend on the current stock being analised and the current sampling frequency (daily, weekly etc.). They must be bound to the appropriate procedures just in the scope where the indicators are being run. In Common Lisp this is easily done with special variables. In Scheme we have the SRFI-39, <a href="http://srfi.schemers.org/srfi-39/srfi-39.html" title="Parameter objects">Parameter objects</a>. But since the parameter objects act syntatically like closures, using them directly would demand that the indicator writer use a cumbersome syntax like:</p>

<div class="wp_codebox"><table><tr id="p411"><td class="code" id="p4code11"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>indicator force<span style="color: #66cc66;">-</span>index <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Force Index&quot;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>closing<span style="color: #66cc66;">&#41;</span> <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> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>closing<span style="color: #66cc66;">&#41;</span> x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>volume<span style="color: #66cc66;">&#41;</span> x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>This is very undesirable. The solution, in face of the lack of special variables, is to use a code walker. Due to the unique syntax of Lisp, this whole process can be combined into a simple macro:</p>

<div class="wp_codebox"><table><tr id="p412"><td class="code" id="p4code12"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>macro <span style="color: #66cc66;">&#40;</span>indicator name args desc . body<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">letrec</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>helpers '<span style="color: #66cc66;">&#40;</span>opening closing maximum minimum
                      volume num<span style="color: #66cc66;">-</span>operations num<span style="color: #66cc66;">-</span>stocks
                      num<span style="color: #66cc66;">-</span>samples<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
           <span style="color: #66cc66;">&#40;</span>walker <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>sexp<span style="color: #66cc66;">&#41;</span>
                     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">pair?</span> sexp<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>opr <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> sexp<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                               <span style="color: #66cc66;">&#40;</span>args <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> sexp<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                           <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">memq</span> opr helpers<span style="color: #66cc66;">&#41;</span>
                               <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> `<span style="color: #66cc66;">&#40;</span>,opr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> walker args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                               <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> opr <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> walker 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>
                         sexp<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;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>,name <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> ,args ,@<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> walker 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;">&#40;</span><span style="color: #b1b100;">set!</span> <span style="color: #66cc66;">*</span>indicator<span style="color: #66cc66;">-</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> ,desc ,name<span style="color: #66cc66;">&#41;</span>
                                    <span style="color: #66cc66;">*</span>indicator<span style="color: #66cc66;">-</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">*</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></pre></td></tr></table></div>

<p>And that&#8217;s it. From now on I need to think only about indicators, and not where to put them, how to supply them helpers, what&#8217;s the frequency of their samples etc. They are high-level abstractions which are now part of my language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/04/dsls-are-cool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
