<?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>nklein software &#187; scheme</title>
	<atom:link href="http://nklein.com/tags/scheme/feed/" rel="self" type="application/rss+xml" />
	<link>http://nklein.com</link>
	<description>software development and consulting</description>
	<lastBuildDate>Wed, 30 Jun 2010 14:00:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Burnt Paper plugin for GIMP</title>
		<link>http://nklein.com/2010/02/burnt-paper-plugin-for-gimp/</link>
		<comments>http://nklein.com/2010/02/burnt-paper-plugin-for-gimp/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 21:29:16 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Initial Releases]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[gimp]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1227</guid>
		<description><![CDATA[Yesterday, I decided to make the images in my article look like they were on old, burnt paper.  I did this manually in the GIMP.
I liked the effect, but I didn&#8217;t want the tedium of having to do all n steps manually next time I go to use it.  So, I wrote a [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I decided to make the images in <a href="http://nklein.com/2010/02/finding-the-perfect-hyperbola/">my article</a> look like they were on old, burnt paper.  I did this manually in <a href="http://gimp.org/">the GIMP</a>.</p>
<p>I liked the effect, but I didn&#8217;t want the tedium of having to do all n steps manually next time I go to use it.  So, I wrote a GIMP plugin script to do it.</p>
<p>Here is an example of the plugin script in action.  As you can see, I started with a text layer and a selection that was bigger than the text layer.  The plugin uses the selection size as original edge of the paper (original, as in before the paper was burned).<br />
<center><a href="http://nklein.com/wp-content/uploads/2010/02/original-image.png"><img src="http://nklein.com/wp-content/uploads/2010/02/original-image.png" alt="" title="original-image" width="600" height="281" class="alignnone size-full wp-image-1228" /></a></center></p>
<p>And, here is the resulting image:<br />
<center><a href="http://nklein.com/wp-content/uploads/2010/02/final-image.png"><img src="http://nklein.com/wp-content/uploads/2010/02/final-image.png" alt="" title="final-image" width="600" height="300" class="alignnone size-full wp-image-1229" /></a></center></p>
<p>Here is the <a href="http://nklein.com/wp-content/uploads/2010/02/burnt-paper.scm">Burnt Paper plugin script</a>.  Plop this in a directory that&#8217;s in your script search path and refresh GIMP&#8217;s scripting and then you&#8217;ll find it in the <q>Filters &gt; Decor</q> menu.  [You can see the script search path by going to <q>Edit &gt; Preferences</q> and selecting <q>Scripts</q> under <q>Folders</q> in the left sidebar.  And, you can refresh the scripts by going to <q>Filters &gt; Script-Fu &gt; Refresh Scripts</q>.]</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2010/02/burnt-paper-plugin-for-gimp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>TC Lispers, July Presentations Online</title>
		<link>http://nklein.com/2009/07/tc-lispers-july-presentations-online/</link>
		<comments>http://nklein.com/2009/07/tc-lispers-july-presentations-online/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 15:58:44 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[TC Lisp]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[slime]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=682</guid>
		<description><![CDATA[The July meeting of the Twin Cities Lisp Users Group was this past Tuesday.  There were four presentations on the agenda:

Meet the Macro by Patrick Stein
Lisp and Scheme by Grant Rettke
Hygienic Macros by Grant Rettke
SLIME introduction by Anthony Juckel

The presentation slides and videos of the talks are available through the links above, and directly [...]]]></description>
			<content:encoded><![CDATA[<p>The July meeting of the Twin Cities Lisp Users Group was this past Tuesday.  There were four presentations on the agenda:</p>
<ul>
<li><a href="http://tclispers.org/meet-macro">Meet the Macro</a> by <a href="http://nklein.com/">Patrick Stein</a></li>
<li><a href="http://tclispers.org/lisp-and-scheme">Lisp and Scheme</a> by <a href="http://wisdomandwonder.com/">Grant Rettke</a></li>
<li><a href="http://tclispers.org/hygienic-macros">Hygienic Macros</a> by <a href="http://wisdomandwonder.com/">Grant Rettke</a></li>
<li><a href="http://tclispers.org/slime-introduction">SLIME introduction</a> by Anthony Juckel</li>
</ul>
<p>The presentation slides and videos of the talks are available through the links above, and directly at the <a href="http://tclispers.org/">tclispers.org</a> site.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2009/07/tc-lispers-july-presentations-online/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why Not Return A Function?</title>
		<link>http://nklein.com/2009/07/why-not-return-a-function/</link>
		<comments>http://nklein.com/2009/07/why-not-return-a-function/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 19:19:08 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=633</guid>
		<description><![CDATA[This morning, I was catching up on the RSS feeds I follow.  I noticed an interesting snippet of code in the Abstract Heresies journal for the Discrete-time Fourier Transform.  Here is his snippet of code:
&#40;define &#40;dtft samples&#41;
&#160; &#40;lambda &#40;omega&#41;
&#160; &#160; &#40;sum 0 &#40;vector-length samples&#41;
&#160; &#160; &#160; &#160; &#40;lambda &#40;n&#41;
&#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This morning, I was catching up on the RSS feeds I follow.  I noticed an interesting snippet of code in the <a href="http://funcall.blogspot.com/">Abstract Heresies</a> journal for the <a href="http://funcall.blogspot.com/2009/06/dtft.html">Discrete-time Fourier Transform</a>.  Here is his snippet of code:</p>
<div class="codecolorer-container scheme blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scheme codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>dtft samples<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>omega<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>sum <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector-length</span> samples<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector-ref</span> samples n<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">make-polar</span> <span style="color: #cc66cc;">1.0</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> omega n<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></div></div>
<p>My first thought was <q>That&#8217;s way too short.</q>  Then, I started reading through it.  My next thought was, maybe I don&#8217;t understand scheme at all.  Then, my next thought was, <q>I do understand this code, it just didn&#8217;t do things the way I expected.</q></p>
<p>Here, I believe is a decent translation of the above into Common Lisp:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> dtft <span style="color: #66cc66;">&#40;</span>samples<span style="color: #66cc66;">&#41;</span><br />
&nbsp; #'<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>omega<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>loop for nn from <span style="color: #cc66cc;">0</span> below <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> samples<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;summing <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>angle <span style="color: #66cc66;">&#40;</span>* omega nn<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>* <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">aref</span> samples nn<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>complex <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cos</span> angle<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">sin</span> angle<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></div></div>
<p>Now, what I find most interesting here is that most implementations you&#8217;ll find for the DTFT (Discrete-Time Fourier Transform) take an array of samples and a wavelength, and returns a result.  This, instead, returns a function which you can call with a wavelength <em>omega</em>.  It returns an evaluator.  This is an interesting pattern that I will have to try to keep in mind.  I have used it in some places before.  But, I am sure there are other places that I should have used it, and missed.  This is one where I would have missed.</p>
<p>Usage for the above would go something like:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>dd <span style="color: #66cc66;">&#40;</span>dtft samples<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>dd angle1<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>dd angle2<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>For those not into Lisp either (who are you?), here is a rough translation into C++.</p>
<div class="codecolorer-container cpp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339900;">#include &lt;cmath&gt;</span><br />
<span style="color: #339900;">#include &lt;complex&gt;</span><br />
<br />
<span style="color: #0000ff;">class</span> DTFT <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> len<span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #0000ff;">double</span><span style="color: #000040;">*</span> samples<span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; DTFT<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">double</span><span style="color: #000040;">*</span> _samples, <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> _len <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>len <span style="color: #000080;">=</span> _len<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>samples <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">double</span><span style="color: #008000;">&#91;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>len <span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> ii<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> ii <span style="color: #000080;">&lt;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>len<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>ii <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>samples<span style="color: #008000;">&#91;</span> ii <span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> _samples<span style="color: #008000;">&#91;</span> ii <span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; ~DTFT<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">delete</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>samples<span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; std<span style="color: #008080;">::</span><span style="color: #007788;">complex</span><span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">double</span> <span style="color: #000080;">&gt;</span> operator <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">double</span> omega <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; std<span style="color: #008080;">::</span><span style="color: #007788;">complex</span><span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">double</span> <span style="color: #000080;">&gt;</span> sum<span style="color: #008000;">&#40;</span> <span style="color:#800080;">0.0</span>, <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> ii<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> ii <span style="color: #000080;">&lt;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>len<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>ii <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; sum <span style="color: #000040;">+</span><span style="color: #000080;">=</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>samples<span style="color: #008000;">&#91;</span> ii <span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> std<span style="color: #008080;">::</span><span style="color: #007788;">polar</span><span style="color: #008000;">&#40;</span> <span style="color:#800080;">1.0</span>, omega <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> sum<span style="color: #008080;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></div></div>
<p>With usage like:</p>
<div class="codecolorer-container cpp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DTFT dd<span style="color: #008000;">&#40;</span> samples, <span style="color: #0000dd;">1024</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
dd<span style="color: #008000;">&#40;</span> angle1 <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
dd<span style="color: #008000;">&#40;</span> angle2 <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
...</div></div>
<p>So, six lines of Scheme or Lisp.  Twenty-five lines of C++ including explicit definition of a class to act as a pseudo-closure, explicit copying and management of the samples buffer, etc.  I suppose, a more direct translation would have used a <em>std::vector</em> to hold the samples and would have just kept a pointer to the buffer.  That would have shaved off six or seven lines and the whole <em>len</em> and <em>_len</em> variables.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2009/07/why-not-return-a-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
