<?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; scheme</title>
	<atom:link href="http://www.artisancoder.com/tag/scheme/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artisancoder.com</link>
	<description>Software development as a craft</description>
	<lastBuildDate>Mon, 23 Aug 2010 13:19:58 +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>Babel Syndrome</title>
		<link>http://www.artisancoder.com/2010/01/babel-syndrome/</link>
		<comments>http://www.artisancoder.com/2010/01/babel-syndrome/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:10:06 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Scheme]]></category>
		<category><![CDATA[r7rs]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[standard]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=156</guid>
		<description><![CDATA[At this moment the groups that will bring us the seventh revision of the report on the algorithmic language Scheme (R7RS), which is going to be split in two, are being formed. I just hope that they keep in mind that even the gods will fear us if they succeed at producing a report (or [...]]]></description>
			<content:encoded><![CDATA[<p>At this moment the groups that will bring us the seventh revision of the report on the algorithmic language Scheme (R7RS), which is going to be split in two, are being formed. I just hope that they keep in mind that even the gods will fear us if they succeed at producing a report (or reports) that the vast majority of us like:</p>
<p>
<blockquote>
&#8220;If now, while they are one people, all speaking the same language, they have started to do this, nothing will later stop them from doing whatever they propose to do.&#8221; &#8211; Genesis XI, v.6
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2010/01/babel-syndrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a garbage collector</title>
		<link>http://www.artisancoder.com/2009/05/adding-a-garbage-collector/</link>
		<comments>http://www.artisancoder.com/2009/05/adding-a-garbage-collector/#comments</comments>
		<pubDate>Tue, 05 May 2009 15:00:12 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=96</guid>
		<description><![CDATA[I guess it is clear by now that I am writing a toy Scheme compiler and virtual machine. Primarily for learning the techniques, I just touch it from time to time. The last addition to the virtual machine was a Cheney-style copy garbage collector. I wanted to implement a very simple algorithm to get a [...]]]></description>
			<content:encoded><![CDATA[<p>I guess it is clear by now that I am writing a toy Scheme compiler and virtual machine. Primarily for learning the techniques, I just touch it from time to time. The last addition to the virtual machine was a <a href="http://en.wikipedia.org/wiki/Cheney%27s_algorithm" title="Cheney's algorithm">Cheney-style</a> copy garbage collector. I wanted to implement a very simple algorithm to get a functioning system quicker. The simplest algorithms I know of are the Cheney one and the <a href="http://portal.acm.org/citation.cfm?id=363554&#038;dl=GUIDE&#038;coll=GUIDE&#038;CFID=34360320&#038;CFTOKEN=66444289" title="An efficient machine-independent procedure for garbage collection in various list structures">Deutsch-Schorr-Waite</a> mark-and-sweep garbage collector. I chose the copying one because I believe generational garbage collection is the way to go for Scheme virtual machines, given that the rate of allocation is very high (allocation in a copy garbage collector is just moving a pointer) and most data objects die young (how many times did you use <tt>reverse</tt> after a loop?).</p>
<p>I was surprised by how easy it was to implement the collector. It is a very simple one (stop-the-world, two semi-spaces etc.) but nevertheless I always thought garbage collectors were somewhat magical, a bunch of elves that worked out of sight to keep your process working perfectly. This is exactly why I am writing such a system, even if it never gets free onto the world it will fulfill its purpose. Of course, if I am satisfied with the result, I will release the beast.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2009/05/adding-a-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My voter registration</title>
		<link>http://www.artisancoder.com/2009/02/my-voter-registration/</link>
		<comments>http://www.artisancoder.com/2009/02/my-voter-registration/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 17:57:32 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Scheme]]></category>
		<category><![CDATA[comittee]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[voting]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=91</guid>
		<description><![CDATA[The voter registration period for the Scheme Steering Comittee is over. I thought I could then post my statement of interest: I have been using Scheme for almost four years now. I use it mostly for studying programming languages and programming in general, prototyping and testing new ideas, but I have also developed and sold [...]]]></description>
			<content:encoded><![CDATA[<p>The voter registration period for the Scheme Steering Comittee is over. I thought I could then post my statement of interest:</p>
<blockquote>
<p>I have been using Scheme for almost four years now. I use it mostly for studying programming languages and programming in general, prototyping and testing new ideas, but I have also developed and sold applications written in Scheme to customers. I believe Scheme is nowadays a maximum in the design space of programming languages and is the language of choice of some of the best hackers of the world. I thus deeply wish that Scheme gets getter with each new standard revision.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2009/02/my-voter-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling let</title>
		<link>http://www.artisancoder.com/2009/01/compiling-let/</link>
		<comments>http://www.artisancoder.com/2009/01/compiling-let/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 18:54:42 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=78</guid>
		<description><![CDATA[Following my previous Scheme toy interpreter in Lua, I have already tried twice to write a simple Scheme compiler. I failed mostly because the complexity grew too fast and I could not see any of it working before losing interest. But I then read Ghuloum&#8217;s paper on incremental compiler construction. It&#8217;s a very nice approach, [...]]]></description>
			<content:encoded><![CDATA[<p>Following my previous <a href="http://www.artisancoder.com/2008/06/toy-scheme-interpreter-in-lua/" title="Toy Scheme interpreter in Lua">Scheme toy interpreter in Lua</a>, I have already tried twice to write a simple Scheme compiler. I failed mostly because the complexity grew too fast and I could not see any of it working before losing interest. But I then read <a href="http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf" title="An Incremental Approach to Compiler Construction">Ghuloum&#8217;s paper</a> on incremental compiler construction. It&#8217;s a very nice approach, and I stopped trying to think everything in advance and instead started to work little by little. Unlike the paper I&#8217;m not compiling to assembly but to a virtual machine, tough.</p>
<p>I have come across one of the many design decisions a compiler writer faces. When compiling <tt>let</tt> forms, they are first translated to the closed lambda applications they are syntatic sugar for. For instance:</p>

<div class="wp_codebox"><table><tr id="p783"><td class="code" id="p78code3"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a <span style="color: #ff0000;">&quot;Alex&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> pi <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">0</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><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> a <span style="color: #66cc66;">+</span> <span style="color: #66cc66;">-</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">e</span> i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Becomes:</p>

<div class="wp_codebox"><table><tr id="p784"><td class="code" id="p78code4"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>a <span style="color: #b1b100;">e</span> i<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> a <span style="color: #66cc66;">+</span> <span style="color: #66cc66;">-</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">e</span> i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
 <span style="color: #ff0000;">&quot;Alex&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> pi <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">0</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>There is no need to emit code to create full closures when compiling closed lambda applications, because they cannot be applied multiple times. Instead, the environment is extended during compilation and the body is compiled in this new environment, but still it is considered just a piece of the enclosing body. So far so good, but what does happen during execution?</p>
<p>During the execution of the virtual machine, the arguments to full closures are pushed onto the stack (along with a return address, saved frame pointer and number of arguments pushed), before jumping to the closure code. Currently, when entering the body of closed lambda applications, a lightweight closure calling protocol is used: Just the frame pointer and the arguments are pushed onto the stack and are latter popped. But when accessing bindings not local to the current scope, which is very common in <tt>let</tt> forms when one access the arguments of the enclosing full closure, the compiler has to emit code for jumping through activation frames until the desired one is found, and the binding is found there. In other words, the VM instruction for accessing bindings is <tt>LOAD i j</tt>, where <tt>i</tt> is the activation frame level and <tt>j</tt> is the index of the binding inside that activation frame.</p>
<p>Although this works, it is not as fast as it could be. I am planning to use flat environments as described in <a href="http://www.cs.indiana.edu/~dyb/pubs/3imp.pdf" title="Three Implementation Models for Scheme">Dybvig&#8217;s PhD thesis</a> so all access to bindings inside closures will have constant time, not linear on the depth of the desired binding. The current compilation of closed lambda applications defeats that optimisation, although it makes bindings somewhat shallower. The alternative is to look for all the bindings introduced by closed lambda applications during compilation and always allocate space for all of them in the stack. This uses (possibly much) more memory because allocates space for bindings that may never be needed during execution, but accessing any binding is again constant time because all of them are known at compile time.</p>
<p>As usual, it boils down to memory versus speed. I guess I&#8217;ll leave it as is for now and worry more about speed after the compiler is able of even compiling itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2009/01/compiling-let/feed/</wfw:commentRss>
		<slash:comments>1</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>Meroon for Gambit-C</title>
		<link>http://www.artisancoder.com/2008/10/meroon-for-gambit-c/</link>
		<comments>http://www.artisancoder.com/2008/10/meroon-for-gambit-c/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 03:21:35 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[meroon]]></category>
		<category><![CDATA[object-orientation]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=46</guid>
		<description><![CDATA[Meroon is a Scheme object system by Christian Queinnec. It is portable, fast, CLOS-like and reflexive. The Meroon home page cites versions for several popular Scheme systems, including Gambit-C. But the links to the Gambit-C version are broken. Doing a bit of research, that actually involved some guessing, I found the Meroon Gambit-C port in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/Meroon.html" title="Meroon">Meroon</a> is a Scheme object system by <a href="http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/Queinnec.html" title="Christian Queinnec">Christian Queinnec</a>. It is portable, fast, CLOS-like and reflexive. The Meroon home page cites versions for several popular Scheme systems, including <a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page" title="Gambit-C">Gambit-C</a>. But the links to the Gambit-C version are broken. Doing a bit of research, that actually involved some guessing, I found the <a href="http://www.math.purdue.edu/~lucier/meroon.tar.gz" title="Meroon">Meroon Gambit-C port</a> in <a href="http://www.math.purdue.edu/~lucier/" title="Bradley Lucier">Bradley Lucier&#8217;s home page</a>. Instructions to build this Meroon port can be found in <a href="https://webmail.iro.umontreal.ca/pipermail/gambit-list/2006-February/000619.html" title="Gambit and Meroon">this thread</a> in the Gambit-C mailing list.</p>
<p>I am not a heavy user of <a href="http://en.wikipedia.org/wiki/Object-oriented_programming" title="Object-oriented programming">object orientation</a>, but I can certainly see its value where it is worth. In the <a href="http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiSP.html" title="Lisp in Small Pieces">LiSP book</a>, for instance, a beautiful interpreter and a compiler are written in OO-style, in chapter 3 and 10, respectively. Another example is writing a scene graph for a Computer Graphics application, it almost begs to be written object-oriented.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/10/meroon-for-gambit-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The need for speed</title>
		<link>http://www.artisancoder.com/2008/09/the-need-for-speed/</link>
		<comments>http://www.artisancoder.com/2008/09/the-need-for-speed/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 21:05:59 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=35</guid>
		<description><![CDATA[I have found a very interesting thread in the Gambit-C Scheme mailing list. Marc Feeley tries to dismiss the myth that floating-point calculations are inherently faster in C/C++ than in Scheme, which is taken as common wisdom. The the work of Bradley Lucier is cited as a case of very fast numerical Scheme code. Bradley [...]]]></description>
			<content:encoded><![CDATA[<p>I have found a <a href="https://webmail.iro.umontreal.ca/pipermail/mslug/2007-December/000241.html" title="Floating point speed of Gambit-C">very interesting thread</a> in the <a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page" title="Gambit-C">Gambit-C Scheme</a> mailing list. Marc Feeley tries to dismiss the myth that floating-point calculations are inherently faster in C/C++ than in Scheme, which is taken as common wisdom. The the work of Bradley Lucier is cited as a case of very fast numerical Scheme code.
<p>Bradley himself <a href="https://webmail.iro.umontreal.ca/pipermail/mslug/2007-December/000251.html" title="Floating point speed of Gambit-C">replies</a>, in which he explains that his code is roughly half as fast as it would have been if coded in C, but the memory bandwidth is the culprit and it does not matter anyway. An interesting part of the email is this:</p>
<blockquote><p>I didn&#8217;t mind rewriting the level-1 BLAS code in Scheme, however, as   it didn&#8217;t seem worth the trouble to get a small speedup in the entire   system just to use a dot-product or saxpy written in C and called   from an FFI.  I have enough difficulty in getting students to admit to themselves that, yes, this system is fast (just about as fast as any expert could have written it, and probably much faster than your average graduate student could have written it) and it&#8217;s flexible (it&#8217;s only at the end of the course that some students reluctantly admit that they could not have finished their semester project in their favorite language, whether C or C++), and that the speed doesn&#8217;t arise from level-1 BLAS written in C (because they&#8217;re written   in Scheme).  One point that most students seem to take away from the class is that multigrid is one hell of a lot faster than conjugate gradient, and many of them have been using conjugate gradient in their own projects simply because it&#8217;s too hard to program multigrid in C or C++ (at least the first time you try it). So one gets a lot of speedup simply by being able to program more sophisticated algorithms.</p>
</blockquote>
<p>There is also a toy ray-tracer written in Gambit-C, <a href="http://smallnum.blogspot.com/2007/10/scheme-raytracer-written-in-couple-of.html" title="Scheme Raytracer written in a couple of days">Schemeray</a>, which was further <a href="http://smallnum.blogspot.com/2007/10/scheme-raytracer-optimized.html" title="Scheme Raytracer Optimized">optimised</a> by Marc Feeley, and <a href="https://webmail.iro.umontreal.ca/pipermail/gambit-list/2008-March/002235.html" title="Updated Schemeray">even more</a> by (again) Bradley Lucier. The times are impressive, thanks to all the clever compiler tricks Gambit-C uses when generating C code, like inlining, partial code evaluation and generating one C function per Scheme module (avoiding expensive inter-module C calls).</p>
<p>The code generated by Gambit-C is fast enough for 99.99% of the applications out there. And this is using a <em>strong, dynamically-typed</em> language, with first-class closures and continuations, arbitrary-precision numbers, and the powerful macros of the Lisp family of languages. There is hardly need to use C or C++ even in the most demanding applications. The same cannot be said of Perl, Python or Ruby, whose applications usually run much slower than one created with Gambit-C. And, if the need <strong>really</strong> arises, interfacing Gambit-C with C code is extremely easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/09/the-need-for-speed/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>
	</channel>
</rss>
