<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Mithro rants about stuff - scheme</title>
    <description>Technical blog about open source hardware, software development, and tech projects. Documenting work on HDMI2USB, TimVideos.us, and various hardware/software initiatives. - Posts in scheme category</description>
    <link>https://blog.mithis.net/</link>
    <atom:link href="https://blog.mithis.net/archives/category/scheme/feed/" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 31 May 2026 10:37:31 +1000</pubDate>
    <lastBuildDate>Sun, 31 May 2026 10:37:31 +1000</lastBuildDate>
    <generator>Jekyll v4.4.1</generator>
    <language>en-US</language>
    <webMaster>tim@mithis.net (Mithro rants about stuff)</webMaster>
    <managingEditor>tim@mithis.net (Mithro rants about stuff)</managingEditor>

    
    
      <item>
        <title>Skimpy, Scheme in Python</title>
        <description>&lt;p&gt;For something a bit different, I decided to work on making embedding &lt;a href=&quot;http://www.schemers.org/&quot;&gt;Scheme&lt;/a&gt; in &lt;a href=&quot;http://www.python.org/&quot;&gt;Python&lt;/a&gt; easier. I’ve previously been using the cool &lt;a href=&quot;http://http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/&quot;&gt;PyScheme&lt;/a&gt;, however it hasn’t been updated in quite a long time (since 2004) and is quite slow.&lt;/p&gt;

&lt;p&gt;The reason I would want to do something crazy like this is that &lt;a href=&quot;http://www.thousandparsec.net/&quot;&gt;Thousand Parsec&lt;/a&gt; use a subset of Scheme called &lt;a href=&quot;http://www.thousandparsec.net/tp/dev/documents/ncl.php&quot;&gt;TPCL&lt;/a&gt;. The is used to transmit information from the server to clients about rules for creating designs. Servers also need to be able to parse &lt;a href=&quot;http://www.thousandparsec.net/tp/dev/documents/ncl.php&quot;&gt;TPCL&lt;/a&gt; for “dumb clients” which can’t parse &lt;a href=&quot;http://www.thousandparsec.net/tp/dev/documents/ncl.php&quot;&gt;TPCL&lt;/a&gt; for themselves.&lt;/p&gt;

&lt;p&gt;Recent developments by &lt;a href=&quot;http://dystopicfro.blogspot.com/index.html&quot;&gt;DystopicFro&lt;/a&gt; on his &lt;a href=&quot;http://code.google.com/soc&quot;&gt;Summer of Code&lt;/a&gt; project, a &lt;a href=&quot;http://git.thousandparsec.net/gitweb/gitweb.cgi?p=tpruledev.git;a=summary&quot;&gt;Ruleset&lt;/a&gt;&lt;a href=&quot;http://git.thousandparsec.net/gitweb/gitweb.cgi?p=tpruledev.git;a=summary&quot;&gt; Development Environment&lt;/a&gt; have meant that he also needs the ability to parser &lt;a href=&quot;http://www.thousandparsec.net/tp/dev/documents/ncl.php&quot;&gt;TPCL&lt;/a&gt; (and specifically the ability to detect errors). This got us chatting about PyScheme and it’s inadequacies.&lt;/p&gt;

&lt;p&gt;What I have decided to do is create a module called &lt;a href=&quot;http://git.thousandparsec.net/gitweb/gitweb.cgi?p=schemepy.git;a=summary&quot;&gt;SchemePy&lt;/a&gt; (pronounced Skimpy). On platforms where speed is of no concern, we will fall back to using a modified version of PyScheme. However, we can also use C scheme systems such as &lt;a href=&quot;http://www.gnu.org/software/guile/guile.html&quot;&gt;Guile&lt;/a&gt; (or other libraries) to improve speed.&lt;/p&gt;

&lt;p&gt;Why have multiple implementations? It stops us from using custom things in one scheme implementation which are not compatible with other implementations. It also makes installation easier for the user, as they are much more likely to already have a compatible scheme library installed. Different scheme’s also have different speed advantages.&lt;/p&gt;

&lt;p&gt;So far I have got the &lt;a href=&quot;http://www.gnu.org/software/guile/guile.html&quot;&gt;Guile&lt;/a&gt; wrapper 95% working. It’s written mainly in &lt;a href=&quot;http://www.python.org/&quot;&gt;Python&lt;/a&gt; using &lt;a href=&quot;http://python.net/crew/theller/ctypes/&quot;&gt;ctypes&lt;/a&gt;. I needed a small C helper module as well because of the extensive Macro’s used by Guile. So far, you can convert between Guile and Python types easily, you can register Python functions into the Guile context and exceptions are caught. There is also the ability to pass  python objects thru the Scheme environment to Python functions. I would like to thank the guys who hang out on &lt;a href=&quot;irc://irc.freenode.org/#guile&quot;&gt;#guile&lt;/a&gt; for all their help, it has made doing this wrapper much easier.&lt;/p&gt;

&lt;p&gt;I’m happy enough with the outcome. My guess it will be between 10 and 20 times faster then PyScheme, but I’ve yet to do any benchmarking. I’m going to move to wrapping &lt;a href=&quot;http://www.plt-scheme.org/software/mzscheme/&quot;&gt;mzscheme&lt;/a&gt; too soon enough. It should be much easier to do now that I have gotten most of the hard stuff sorted out. I think a lot of it will be common between the implementations.&lt;/p&gt;

&lt;p&gt;What I really need to do is get a test-suit working. Once I have more then one implementation working  it will be very important to make sure that they all work the same way, the only way I can see to do that properly is to have a test suite which I can run every implementation against.&lt;/p&gt;

&lt;p&gt;One thing which might be really cool to investigate is using a similar system to &lt;a href=&quot;http://web.archive.org/web/20040607171956/http://www.caddr.com/code/lython/&quot;&gt;lython&lt;/a&gt; which compiles Lisp &lt;a href=&quot;http://en.wikipedia.org/wiki/Sexp&quot;&gt;s-expressions&lt;/a&gt; directly to python byte code. If this was done well it should be the fastest method as it would mean no type conversion needs to be done.&lt;/p&gt;

&lt;p&gt;Overall this has been quite a good learning experience. I have improve my ctype skills quite a lot (this wasn’t my first ctypes wrapper, that being &lt;a href=&quot;http://git.thousandparsec.net/repos/libmng-py/doc/&quot;&gt;libmng-py&lt;/a&gt;, a Python wrapper around &lt;a href=&quot;http://www.libmng.com/&quot;&gt;libmng&lt;/a&gt;). I also understand how &lt;a href=&quot;http://www.schemers.org/&quot;&gt;Scheme&lt;/a&gt; works quite a lot better now.&lt;/p&gt;
</description>
        <pubDate>Mon, 23 Jul 2007 03:06:02 +1000</pubDate>
        <link>https://blog.mithis.net/archives/tp/45-schemepy</link>
        <guid isPermaLink="true">https://blog.mithis.net/archives/tp/45-schemepy</guid>
        
        
        <category>tp</category>
        
        <category>scheme</category>
        
        <category>python</category>
        
        
        <description>For something a bit different, I decided to work on making embedding Scheme in Python easier. I’ve previously been using the cool PyScheme, however it hasn’t been updated in quite a long time (since.....</description>
        
      </item>
    
  </channel>
</rss>
