<?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>bloggo ergo sum &#187; Lisp</title>
	<atom:link href="http://bloggoergosum.com/tag/lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://bloggoergosum.com</link>
	<description></description>
	<lastBuildDate>Mon, 10 Oct 2011 04:42:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Continuations</title>
		<link>http://bloggoergosum.com/2009/02/03/continuations/</link>
		<comments>http://bloggoergosum.com/2009/02/03/continuations/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 16:48:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://bloggoergosum.com/?p=366</guid>
		<description><![CDATA[By training and experience, I&#8217;m largely an object-oriented programmer. I was a freshman comp. sci. student when the Java wave hit my university, so that&#8217;s what I was fed. I didn&#8217;t learn anything else but Java until the summer after my sophomore year; then, I was involved in a summer research program for which I [...]]]></description>
			<content:encoded><![CDATA[<p>By training and experience, I&#8217;m largely an object-oriented programmer.  I was a freshman comp. sci. student when the Java wave hit my university, so that&#8217;s what I was fed.  I didn&#8217;t learn anything else but Java until the summer after my sophomore year; then, I was involved in a summer research program for which I used C++.  Between then and the end of my undergraduate tenure, I had picked up more C++ and learned C (I should add here that my department was and is a very good c.s. department &#8211; they just didn&#8217;t use functional languages as teaching tools).</p>
<p>Where did that leave me?  I knew how to write nice object hierarchies, tight structural/procedural code.  However, Boost wasn&#8217;t a big deal yet, and I had only barely dabbled in anything else, so I was missing a huge piece of the puzzle: functional programming.  I used lisp for a couple of programming assignments in graduate school because I wanted to learn the language &#8211; and I did learn the basics, but what I didn&#8217;t learn was important functional concepts.</p>
<p>Now, as a working professional programmer, I&#8217;m still trying to learn functional concepts.  Some are pretty easy: immutability and recursive computation.  These are very basic &#8211; even recursive functions were taught in Java programming classes.</p>
<p>But the most interesting element of functional programming is <em>higher order functions</em>, which are the basis for some very powerful forms of abstraction.  This is what I was really missing in my repertoire.</p>
<p>So now, the point:  I&#8217;ve been trying to learn a web framework called <a href="http://weblocks.viridian-project.de/">Weblocks</a>.  It&#8217;s freaking cool &#8211; but it makes heavy use of continuations for control flow (one of its major features).  I had never learned about continuations before, so this was (and still is, to some degree) making it hard to learn the framework.  So I was reading about continuations online (<a href="http://failex.blogspot.com/">here </a>,<a href="http://common-lisp.net/project/cl-cont/">here</a>, and <a href="http://www.defmacro.org/ramblings/continuations-web.html">here</a>) and came across a reference to Paul Graham&#8217;s book, <em>On Lisp</em>.  I have a copy that I printed for myself, so I looked up the chapter on Continuations to gain some insight, and found the best explanation I&#8217;ve seen so far:</p>
<blockquote><p>A continuation is a function representing the future of a computation.  Whenever an expression is evaluated, something is waiting for the value it will return.  For example, in </p>
<pre lang="lisp">
(/ (- x 1) 2)
</pre>
<p>when <tt>(- x 1)</tt> is evaluated, the outer <tt>/</tt> expression is waiting for the value, and something else is waiting for <em>its</em> value, and so on and so on, all the way back to the toplevel&#8230;</p>
<p>We can think of the continuation at any given time as a function of one argument.  If the previous expression were typed into the toplevel, then when the subexpression <tt>(- x 1)</tt> was evaluated, the continuation would be:</p>
<pre lang="lisp">
(lambda (val) (/ val 2))
</pre>
<p>That is, the remainder of the computation could be duplicated by calling this function on the return value.
</p></blockquote>
<p>I found the little example shown here to be the best way try to explain continuations.  Trying to understand the <em>applications</em> of continuations is a beast, and without this basic understanding it&#8217;s very easy to get lost. </p>
<p>Now&#8230;back to Weblocks&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://bloggoergosum.com/2009/02/03/continuations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

