<?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>overwatering &#187; scheme</title>
	<atom:link href="http://www.overwatering.org/blog/category/scheme/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.overwatering.org/blog</link>
	<description>Random musings on fish, books and occasionally programming.</description>
	<lastBuildDate>Mon, 07 Nov 2011 07:06:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Ultimate Development Environment</title>
		<link>http://www.overwatering.org/blog/2008/03/the-ultimate-development-environment/</link>
		<comments>http://www.overwatering.org/blog/2008/03/the-ultimate-development-environment/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 10:52:00 +0000</pubDate>
		<dc:creator>giles</dc:creator>
				<category><![CDATA[comp. sci.]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[shrew]]></category>

		<guid isPermaLink="false">http://www.overwatering.org/blog/2008/03/the-ultimate-development-environment/</guid>
		<description><![CDATA[An enormous claim, I know. But this is not about processes, tools or
working conditions. This is about something quite different.

Shrew is
progressing, it now sports an s-expr to XML evaluator; I&#8217;m reading
RESTful Web Services to gain a better idea of how it should expose
resources. And I&#8217;m also working through The Seasoned Schemer. And
therein lies the most [...]]]></description>
			<content:encoded><![CDATA[<p>An enormous claim, I know. But this is not about processes, tools or
working conditions. This is about something quite different.</p>

<p><a href="http://overwatering.blogspot.com/search/label/shrew">Shrew</a> is
progressing, it now sports an s-expr to XML evaluator; I&#8217;m reading
<em>RESTful Web Services</em> to gain a better idea of how it should expose
resources. And I&#8217;m also working through <em>The Seasoned Schemer</em>. And
therein lies the most interesting aspect to Shrew. I am a reasonably
experienced, quite competent polyglot software engineer, but learning
Scheme has forever changed how I think about programming. And through
example crystallised the ultimate development environment that I have
been drifting towards.</p>

<p>When I&#8217;m working on Shrew, my editor looks something like this:</p>

<div style="text-align:center;"><a href="http://www.flickr.com/photos/21818828@N00/2312302048" title="View 'i-scheme-emacs' on Flickr.com"><img src="http://farm4.static.flickr.com/3214/2312302048_65651591d0.jpg" alt="i-scheme-emacs" border="0" width="400" height="300" /></a></div>

<p>In the top-left is the module I am currently working on: writing,
expanding or fixing &#8211; as I&#8217;ll try to show there isn&#8217;t really any
difference between those three. In the top-right is a scratch file
that contains a bunch of ad-hoc tests for the module I&#8217;m working on:
nothing structured, just calls of the functions that I&#8217;m
writing. Across the bottom is the output from a Scheme process running
in the background.</p>

<p>Before I go on there&#8217;s one detail of Scheme I should explain. To write
a new function you call a built-in function called <code>define</code>, passing
the name of the new function and its body. <code>define</code> is smart enough to
simply replace the body if a function of that name already exists.</p>

<p>It sounds like a pretty simple development environment: a plain text
editor with three windows on screen. Why so special?</p>

<p>I write a function &#8211; not a test, sample or prototype, but the real
code I&#8217;m planning to commit &#8211; I jump to the end of the <code>define</code> and
run a command in my editor to evaluate it. That function is then
inserted into the running Scheme process and available to be used by
anything else that is run in that Scheme process. Or, I&#8217;m immediately
informed of a syntax error in my code.</p>

<p>I switch over to the scratch file and write some code to call the
function I just implemented: typically just one expression, but it can
be as many as I need. I evaluate that new code. And immediately see
the output in the window at the bottom; the window reflecting the
running state of the background Scheme process.</p>

<p>And of course, there&#8217;s a bug in my function. I switch back to the
window containing the module, fix the bug and re-evaluate. I switch
back to the test code, re-evaluate that, and see that my change has
fixed the bug.</p>

<p>Elapsed time from writing the function through debugging and verifying
the fix: 45 seconds.</p>

<p>Instead of having to write a complete library, compile it, write a
test harness, compile that and link it to the library and only then
run the code to see if it works, I have a Scheme process running in
the background that I can just keep adding code to. New code, or code
to replace existing code. And at any point I can execute any sub-part
of that process and immediately see the output. No delays, no pauses,
no backtracking to find which line of code is wrong.</p>

<p>Scheme could be regarded as a fairly direct implementation of a
theoretical model of computation: the lambda calculus. Most texts that
teach Scheme emphasise this; they encourage you to think of your
programs in terms of this theory, in quite some detail. That may sound
fairly esoteric, but once you&#8217;ve spent sometime working in this
environment you reach this unique state. You are inside your program,
reaching around moving code as fast as you can think. There is
essentially nothing between your thought and code: no defining
boilerplate, no compiling, no creating test harnesses, no waiting for
test runs to complete. Your solution simply unfolds before you.</p>

<p>But that&#8217;s not to say your code is of lower quality. In fact, because
you&#8217;re concentrating more fully, with no distractions and the
flexibility to easily push your code in any way you want, the code is
of much higher quality. There&#8217;s no idle thought &#8216;I should test that&#8217;
which is forgotten in the edit-compile-run-debug cycle: think it, try
it. This is flow as
<em><a href="http://overwatering.blogspot.com/2007/04/peopleware.html">Peopleware</a></em>
could only dream.</p>

<p>And once you break out of this magical flow, you&#8217;re left with complete
code; code you lived and breathed for a few hours, code you understand
deeply and will have a hard time forgetting. Plus, a comprehensive set
of tests to commit alongside.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overwatering.org/blog/2008/03/the-ultimate-development-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Method Dispatch and Scheme</title>
		<link>http://www.overwatering.org/blog/2007/09/method-dispatch-and-scheme/</link>
		<comments>http://www.overwatering.org/blog/2007/09/method-dispatch-and-scheme/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 04:45:00 +0000</pubDate>
		<dc:creator>giles</dc:creator>
				<category><![CDATA[comp. sci.]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.overwatering.org/blog/2007/09/method-dispatch-and-scheme/</guid>
		<description><![CDATA[As I work
on Shrew
and attempt to learn more
about Scheme,
I&#8217;ve been doing some reading. And in one of my books I had one of
those &#8216;Aha!&#8217; moments where I really saw the benefit in the Scheme way
of doing things.

In object-oriented languages there are two approaches to dispatching
methods.



Message
Passing: Objects are regarded as actors. Method call is
treated as sending [...]]]></description>
			<content:encoded><![CDATA[<p>As I work
on <a href="http://overwatering.blogspot.com/2007/08/what-is-shrew.html">Shrew</a>
and attempt to learn more
about <a href="http://overwatering.blogspot.com/2007/08/thoughts-on-scheme.html">Scheme</a>,
I&#8217;ve been doing some reading. And in one of my books I had one of
those &#8216;Aha!&#8217; moments where I really saw the benefit in the Scheme way
of doing things.</p>

<p>In object-oriented languages there are two approaches to dispatching
methods.</p>

<ul>

<li><span style="font-weight:
bold;"><a href="http://en.wikipedia.org/wiki/Message_passing#OOP">Message
Passing</a></span>: Objects are regarded as actors. Method call is
treated as sending messages to those actors. Method dispatch is
therefore determined solely based upon the type of the receiver of the
method, the types of any arguments is immaterial. SmallTalk typifies
this style. C++, Java and most other OO languages have adopted this
style (badly.) This is also known as single-dispatch.</li>

<li><span style="font-weight:
bold;"><a href="http://en.wikipedia.org/wiki/Multiple_dispatch">Multi-methods</a></span>:
Methods and the objects to which they can be applied are regarded as a
cartesian product: objects don&#8217;t own methods and methods don&#8217;t own
objects. Method dispatch is therefore determined from the type of all
the arguments
equally. <a href="http://en.wikipedia.org/wiki/CLOS">CLOS</a> uses
this style. I am not aware of any other widely used languages that
also use multi-methods.
</li>

</ul>

<p>The book I am currently reading laid out some Scheme code that showed
how to implement multi-methods, and then followed it up with some code
that implemented message passing. In both cases the code was extremely
simple and easy to understand: the basics for two object-oriented
approaches were right there on the page.</p>

<p>And most interestingly, there was no reason why both systems couldn&#8217;t
be used on different objects in the same program.</p>

<p>The book is about general computer science concepts, so it doesn&#8217;t
actually point out what it has just described, and nor does it provide
a complete implementation of an object system (<span style="font-size:
small;">yet&#8230;</span>) however it is interesting to see such a
fundamental part of a object system in so few lines of code. It is the
nature of Scheme that makes it possible to implement things that other
languages regard as &#8216;part of the language&#8217; in your own programs.</p>

<p>It is not possible to do this in Java; it is not possible in C++, not
even
with <a href="http://en.wikipedia.org/wiki/Template_metaprogramming">template
meta-programming</a>; and it isn&#8217;t even in possible in
Haskell<a href="#method-dispatch-note1">*</a>.</p>

<p>Now, that&#8217;s not to say that having both multi-method and message
passing dispatch is itself such a killer feature. But it&#8217;s going to be
kind of hard to beat a language to which both of these things can be
added so simply.</p>

<p><span style="font-size:
x-small;"><a name="method-dispatch-note1">*</a> Of course, via
differing mechanisms of varying degrees of pain, something like
multi-methods could be added to all of these languages. Here I am
talking about a simple, transparent at both caller and callee
technique for achieving multi-methods and message passing.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overwatering.org/blog/2007/09/method-dispatch-and-scheme/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thoughts on Scheme</title>
		<link>http://www.overwatering.org/blog/2007/08/thoughts-on-scheme/</link>
		<comments>http://www.overwatering.org/blog/2007/08/thoughts-on-scheme/#comments</comments>
		<pubDate>Sat, 18 Aug 2007 09:50:00 +0000</pubDate>
		<dc:creator>giles</dc:creator>
				<category><![CDATA[comp. sci.]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[shrew]]></category>

		<guid isPermaLink="false">http://www.overwatering.org/blog/2007/08/thoughts-on-scheme/</guid>
		<description><![CDATA[There&#8217;s nothing like writing a complex application in a language for
really learning it. I&#8217;ve been able to read and write small pieces of
Scheme for years. And I&#8217;ve known enough of the underpinnings of the
language to write a (very) small Scheme interpreter in the past. But,
part of the point of writing Shrew in Scheme as opposed [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s nothing like writing a complex application in a language for
really learning it. I&#8217;ve been able to read and write small pieces of
Scheme for years. And I&#8217;ve known enough of the underpinnings of the
language to write a (very) small Scheme interpreter in the past. But,
part of the point of writing Shrew in Scheme as opposed to, say, Ruby
is to really learn the language.</p>

<p>I haven&#8217;t been at it for long, but here are some random thoughts and
comments so far. Much of this will change as I figure out how to use
Scheme properly. These comments are also mainly a comparison of the
only other functional language I know
well: <a href="http://haskell.org">Haskell</a>.</p>

<ul>

<li>The syntax is not very clear: everything looks the same. This
prevents you from scanning the code to get a feel for what is
happening. The indentation helps, but fundamentally every operation is
just a parenthesized expression. I am certain that this is just
cultural, with more exposure I&#8217;ll get better at reading; don&#8217;t count
this as a negative.</li>

<li>I really miss pattern matching. How can you program without it?
I&#8217;m going to have to look into <code>destructuring-bind</code>.</li>

<li>Dynamic typing is sweet. As well as all the other benefits,
dynamic typing + modules = as much encapsulation as classes give you
in C++.</li>

<li>The standard libraries are pretty paltry. The SRFIs add a lot, but
it&#8217;s still nowhere near as rich as pretty much any other
language. Maybe I&#8217;ll explore Common Lisp at some point.</li>

<li>Currying is not just an implementation technicality, it&#8217;s useful
for designing data structures. I miss currying as well.</li>

</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.overwatering.org/blog/2007/08/thoughts-on-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

