<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Matt Bowcock // mbowcock.com</title>
	
	<link>http://mbowcock.com</link>
	<description />
	<lastBuildDate>Mon, 09 Jan 2012 20:19:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/mbowcock" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="mbowcock" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Simple Intro to Git</title>
		<link>http://mbowcock.com/links/simple-git-intro/</link>
		<comments>http://mbowcock.com/links/simple-git-intro/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:11:35 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://mbowcock.com/?p=200</guid>
		<description><![CDATA[Looks like a nice intro to Git. Skips a lot of the in-depth details you don&#8217;t necessarily need to get started. http://rogerdudler.github.com/git-guide/]]></description>
			<content:encoded><![CDATA[<p>Looks like a nice intro to Git. Skips a lot of the in-depth details you don&#8217;t necessarily need to get started.</p>
<p><a href="http://rogerdudler.github.com/git-guide/">http://rogerdudler.github.com/git-guide/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/links/simple-git-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roll Your Own OS Links</title>
		<link>http://mbowcock.com/links/roll-your-own-os-links/</link>
		<comments>http://mbowcock.com/links/roll-your-own-os-links/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 20:27:29 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[links]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[os]]></category>

		<guid isPermaLink="false">http://mbowcock.com/?p=192</guid>
		<description><![CDATA[Just a couple of links I&#8217;d like to save for the future. Roll Your Own Toy UNIX-Clone OS &#8211; Less theory and more implementation details. OS Dever Links &#8211; Lots of good stuff here. Especially the &#8216;Lets Build a Compiler&#8217; article.]]></description>
			<content:encoded><![CDATA[<p>Just a couple of links I&#8217;d like to save for the future. </p>
<p><a href="http://www.jamesmolloy.co.uk/tutorial_html/">Roll Your Own Toy UNIX-Clone OS</a> &#8211; Less theory and more implementation details.</p>
<p><a href="http://www.osdever.net/tutorials/index">OS Dever Links</a> &#8211; Lots of good stuff here. Especially the <a href="http://compilers.iecc.com/crenshaw/">&#8216;Lets Build a Compiler&#8217;</a> article.</p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/links/roll-your-own-os-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flat File (Fixed Width) File Generator in C#</title>
		<link>http://mbowcock.com/notebook/flat-file-fixed-width-file-generator-in-c/</link>
		<comments>http://mbowcock.com/notebook/flat-file-fixed-width-file-generator-in-c/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 04:00:09 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://mbowcock.com/?p=184</guid>
		<description><![CDATA[I came up with a custom attribute and class that would allow you to generate a fixed width file from a list of objects. Basically, you create a class to store a file record. Apply the FlatFileAttribute the the class properties describing where a field starts and how long it is. You then pass a [...]]]></description>
			<content:encoded><![CDATA[<p>I came up with a custom attribute and class that would allow you to generate a fixed width file from a list of objects.</p>
<p>Basically, you create a class to store a file record. Apply the FlatFileAttribute the the class properties describing where a field starts and how long it is. You then pass a list of objects of your record type along with a file path to the writeFile method. Out comes a file in the format you specified in your record class.</p>
<p>Check out the code here <a href="https://github.com/mbowcock/flat-file-generator">https://github.com/mbowcock/flat-file-generator</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/flat-file-fixed-width-file-generator-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remap Caps Lock to Ctrl in Ubuntu 11.10</title>
		<link>http://mbowcock.com/notebook/remap-caps-lock-to-ctrl-in-ubuntu-11-10/</link>
		<comments>http://mbowcock.com/notebook/remap-caps-lock-to-ctrl-in-ubuntu-11-10/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 05:19:50 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://mbowcock.com/?p=177</guid>
		<description><![CDATA[I like to remap Caps Lock to Ctrl for use in Vim. Remapping in Ubuntu 11.10 (and recent versions) is pretty easy. System Settings > Keyboard Layout > Options You&#8217;ll be presented with a list of layout options. Click Ctrl key positions and select &#8216;Make Caps Lock an additional Ctrl&#8217;. Done.]]></description>
			<content:encoded><![CDATA[<p>I like to remap Caps Lock to Ctrl for use in Vim. Remapping in Ubuntu 11.10 (and recent versions) is pretty easy. </p>
<p>System Settings > Keyboard Layout > Options </p>
<p>You&#8217;ll be presented with a list of layout options. Click Ctrl key positions and select &#8216;Make Caps Lock an additional Ctrl&#8217;. Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/remap-caps-lock-to-ctrl-in-ubuntu-11-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion Commit Emails on Windows Using Python</title>
		<link>http://mbowcock.com/notebook/subversion-commit-emails-on-windows-using-python/</link>
		<comments>http://mbowcock.com/notebook/subversion-commit-emails-on-windows-using-python/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 03:43:28 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://mbowcock.com/?p=149</guid>
		<description><![CDATA[Setting up subversion commit emails using python on Windows. First things first &#8211; you&#8217;ll need subversion and python installed. Subversion hooks are setup by dropping an executable in the /repositoryPath/hooks/ directory. On Windows this executable needs to be either a .BAT or .CMD file. From this script you can call your python code to perform [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up subversion commit emails using python on Windows.</p>
<p>First things first &#8211; you&#8217;ll need subversion and python installed.</p>
<p>Subversion hooks are setup by dropping an executable in the /repositoryPath/hooks/ directory. On Windows this executable needs to be either a .BAT or .CMD file. From this script you can call your python code to perform any processing. <i>One gotcha on Windows is the $PATH environment variable is not passed so you&#8217;ll need to set this up in your cmd/bat file.</i></p>
<p>My <b>post-commit.cmd</b> file looks like this:</p>
<pre>
<div class="codesnip-container" >@echo off
set REPOS=%1
set REV=%2
set PATH=c:\python31;

python.exe d:\repositories\reponame\hooks\processCommit.py %REPOS% %REV%</div>
</pre>
<p>The post-commit hook gets sent two variables from svn &#8211; the repository and the revision. I save those, set the path, and call processCommit.py.</p>
<p><b>processCommit.py</b></p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">import</span> <span class="kw3">smtplib</span>, <span class="kw3">subprocess</span>, <span class="kw3">sys</span>
<span class="kw1">import</span> <span class="kw3">email</span>.<span class="me1">utils</span>
<span class="kw1">from</span> <span class="kw3">email</span>.<span class="me1">mime</span>.<span class="me1">text</span> <span class="kw1">import</span> MIMEText

repo = <span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span>
rev = <span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>
repository = <span class="st0">'This_is_the_name_in_the_email'</span>
sender = <span class="st0">'subversion@emailserver.com'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1"># Change to any email address</span>

receivers = <span class="br0">&#91;</span><span class="st0">'recp1@your.com'</span>, <span class="st0">'recp2@your.com'</span><span class="br0">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># List of email recipients</span>

<span class="co1"># Get subversion information </span>
<span class="co1"># 'svnlook changed' returns what files / paths have changed</span>
<span class="co1"># 'svnlook info' returns author, date/time, log message</span>
<span class="kw3">cmd</span> = <span class="st0">'c:<span class="es0">\\</span>program files<span class="es0">\\</span>Path to SVN<span class="es0">\\</span>bin<span class="es0">\\</span>svnlook changed %s -r %s'</span> <span class="sy0">%</span> <span class="br0">&#40;</span>repo, rev<span class="br0">&#41;</span>
changed = <span class="kw3">subprocess</span>.<span class="me1">Popen</span><span class="br0">&#40;</span><span class="kw3">cmd</span>, stdout=<span class="kw3">subprocess</span>.<span class="me1">PIPE</span><span class="br0">&#41;</span>.<span class="me1">communicate</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span>0<span class="br0">&#93;</span>
<span class="kw3">cmd</span> = <span class="st0">'c:<span class="es0">\\</span>program files<span class="es0">\\</span>Path to SVN<span class="es0">\\</span>bin<span class="es0">\\</span>svnlook info %s -r %s'</span> <span class="sy0">%</span> <span class="br0">&#40;</span>repo, rev<span class="br0">&#41;</span>
commitMsg = <span class="kw3">subprocess</span>.<span class="me1">Popen</span><span class="br0">&#40;</span><span class="kw3">cmd</span>, stdout=<span class="kw3">subprocess</span>.<span class="me1">PIPE</span><span class="br0">&#41;</span>.<span class="me1">communicate</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>

message = <span class="st0">&quot;&quot;&quot;A commit has been made to the %s repository

*** Commit Information ***

&quot;&quot;&quot;</span> <span class="sy0">%</span> <span class="br0">&#40;</span>repository<span class="br0">&#41;</span>

message = message + commitMsg.<span class="me1">decode</span><span class="br0">&#40;</span><span class="st0">'utf-8'</span><span class="br0">&#41;</span> + <span class="st0">'<span class="es0">\n</span>*** Changed Files ****<span class="es0">\n</span><span class="es0">\n</span>'</span> + changed.<span class="me1">decode</span><span class="br0">&#40;</span><span class="st0">'utf-8'</span><span class="br0">&#41;</span>

msg = MIMEText<span class="br0">&#40;</span>message<span class="br0">&#41;</span>

msg<span class="br0">&#91;</span><span class="st0">'To'</span><span class="br0">&#93;</span> = <span class="st0">', '</span>.<span class="me1">join</span><span class="br0">&#40;</span>receivers<span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1"># Generate string containing recpts. comma separated.</span>

msg<span class="br0">&#91;</span><span class="st0">'From'</span><span class="br0">&#93;</span> = <span class="kw3">email</span>.<span class="me1">utils</span>.<span class="me1">formataddr</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="st0">'Subversion'</span>, <span class="st0">'subversion@emailserver.com'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
msg<span class="br0">&#91;</span><span class="st0">'Subject'</span><span class="br0">&#93;</span> = <span class="st0">'Subversion Commit | %s'</span> <span class="sy0">%</span> <span class="br0">&#40;</span>repository<span class="br0">&#41;</span>

<span class="kw1">try</span>:
&nbsp; &nbsp; &nbsp; &nbsp; session=<span class="kw3">smtplib</span>.<span class="me1">SMTP</span><span class="br0">&#40;</span><span class="st0">'SMTPSERVER'</span><span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp;<span class="co1"># Your SMTP Server</span>
&nbsp; &nbsp; &nbsp; &nbsp; session.<span class="me1">sendmail</span><span class="br0">&#40;</span>sender, receivers, msg.<span class="me1">as_string</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span><span class="br0">&#40;</span><span class="st0">'Notification of commit sent'</span><span class="br0">&#41;</span>
<span class="kw1">except</span> SMTPException:
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span><span class="br0">&#40;</span><span class="st0">'Unable to send notification'</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>svnlook is your friend when writing svn hooks. The core of processCommit.py is using svnlook to retrieve information about what was changed and who changed it. The rest of the code is straigh-forward, basic python. After the information is retrieved from svn, the message is formatted, and sent on it&#8217;s way using email.</p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/subversion-commit-emails-on-windows-using-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim, Tidy, Windows</title>
		<link>http://mbowcock.com/notebook/vim-tidy-windows/</link>
		<comments>http://mbowcock.com/notebook/vim-tidy-windows/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 21:09:24 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>

		<guid isPermaLink="false">http://mbowcock.com/?p=136</guid>
		<description><![CDATA[Getting Vim and Tidy to play nice on Windows. Tidy is a nice little app to pretty-print / beautify your XML (html, etc.). It&#8217;s straight-forward to get working with Vim on Windows. (I assume Vim is already installed) 1. Get the Tidy binary. Drop that somewhere on your system. (I dropped it in the root, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Getting <a href="http://www.vim.org/">Vim</a> and <a href="http://tidy.sourceforge.net/">Tidy</a> to play nice on Windows.</strong></p>
<p>Tidy is a nice little app to pretty-print / beautify your XML (html, etc.).  It&#8217;s straight-forward to get working with Vim on Windows.</p>
<p>(I assume Vim is already installed)</p>
<p>1. Get the <a href="http://prdownloads.sourceforge.net/int64/tidy-060405-exe.zip?download">Tidy binary</a>.  Drop that somewhere on your system.  (I dropped it in the root, c:\)</p>
<p>2. Edit c:\program files\Vim\vim7x\ftplugin\xml.vim<br />
   <em> &#8211; If file doesn&#8217;t exit then create it<br />
    &#8211; For 64-bit os edit &#8211; c:\program files (x86)\&#8230;</em></p>
<div class="codesnip-container" >map &lt;F5&gt; :%! c:\tidy.exe -q -i -xml % &lt;CR&gt;</div>
<p>This will map F5 to run tidy on the current buffer</p>
<p>You can find my <a href="https://github.com/mbowcock/configfiles/blob/master/vim/windows/xml.vim">xml.vim</a> in my github config files repo.</p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/vim-tidy-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webpy Sessions with WSGI</title>
		<link>http://mbowcock.com/notebook/webpy-sessions-with-wsgi/</link>
		<comments>http://mbowcock.com/notebook/webpy-sessions-with-wsgi/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 18:27:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[webpy]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=122</guid>
		<description><![CDATA[I was having trouble getting sessions to work using webpy 0.34 and apache/WSGI and realized late last night what the issue was. I created a basic app and added the obligatory wsgi code - if __name__ == &#34;__main__&#34;:app.run&#40;&#41; #code necessary for wsgi here app = web.application&#40;urls, globals&#40;&#41;, autoreload=False&#41; application = app.wsgifunc&#40;&#41; Then without thinking about [...]]]></description>
			<content:encoded><![CDATA[<p>I was having trouble getting sessions to work using webpy 0.34 and apache/WSGI and realized late last night what the issue was.  </p>
<p>I created a basic app and added the obligatory wsgi code -</p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:app.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span>

<span class="co1">#code necessary for wsgi here</span>
app = web.<span class="me1">application</span><span class="br0">&#40;</span>urls, <span class="kw2">globals</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, autoreload=<span class="kw2">False</span><span class="br0">&#41;</span>
application = app.<span class="me1">wsgifunc</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>Then without thinking about it I went and looked over the examples of session handling in the webpy docs and added the code to create the session store as was shown in the examples.  This code was added to the head of the file just after the imports &#8211; </p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;">store = web.<span class="me1">session</span>.<span class="me1">DiskStore</span><span class="br0">&#40;</span><span class="st0">'sessions'</span><span class="br0">&#41;</span>
app = web.<span class="me1">application</span><span class="br0">&#40;</span>urls, <span class="kw2">globals</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
session = web.<span class="me1">session</span>.<span class="me1">Session</span><span class="br0">&#40;</span>app, store<span class="br0">&#41;</span></div>
</div>
</pre>
<p>This looked good but no luck. Tried disk store and a db store for the sessions and nothing.  Well after a couple of hours of staring at the code I realized I was declaring &#8220;app = &#8230;&#8221; twice in the code.  Once to setup the sessions and then again to setup wsgi.  So to fix I moved the code to handle the wsgi setup to run before the session setup code.  </p>
<p>So now my session and wsgi setup code looks like this.  This code is just after the definition of the URLs -</p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;">urls=<span class="br0">&#40;</span><span class="st0">'/'</span>, <span class="st0">'index'</span><span class="br0">&#41;</span>

<span class="co1">#code necessary for wsgi here</span>
app = web.<span class="me1">application</span><span class="br0">&#40;</span>urls, <span class="kw2">globals</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, autoreload=<span class="kw2">False</span><span class="br0">&#41;</span>
application = app.<span class="me1">wsgifunc</span><span class="br0">&#40;</span><span class="br0">&#41;</span>

<span class="co1">#code for sessions here </span>
store = web.<span class="me1">session</span>.<span class="me1">DiskStore</span><span class="br0">&#40;</span><span class="st0">'sessions'</span><span class="br0">&#41;</span>
session = web.<span class="me1">session</span>.<span class="me1">Session</span><span class="br0">&#40;</span>app, store<span class="br0">&#41;</span></div>
</div>
</pre>
<p>So far this seems to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/webpy-sessions-with-wsgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Video: So You Want to Start a Web Startup (NSFW)</title>
		<link>http://mbowcock.com/post/video-so-you-want-to-start-a-web-startup-nsfw/</link>
		<comments>http://mbowcock.com/post/video-so-you-want-to-start-a-web-startup-nsfw/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 01:57:46 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[post]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=117</guid>
		<description><![CDATA[So You Want to Start a Web Startup]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.youtube.com/watch?v=u6gZ4vk_Tw4&#038;feature=youtube_gdata_player' >So You Want to Start a Web Startup</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/post/video-so-you-want-to-start-a-web-startup-nsfw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 3 in Scheme</title>
		<link>http://mbowcock.com/notebook/project-euler-problem-3-in-scheme/</link>
		<comments>http://mbowcock.com/notebook/project-euler-problem-3-in-scheme/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 18:21:54 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=114</guid>
		<description><![CDATA[Since I&#8217;m working my way through SICP I ended up using some of the code from the examples in section 1.2.6 to search for prime numbers. Six of the eight functions below are used to test if a number is prime. (next-prime &#8230;) just starts at the current prime number and iterate upward until it [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m working my way through SICP I ended up using some of the code from the examples in section 1.2.6 to search for prime numbers.  Six of the eight functions below are used to test if a number is prime.  (next-prime &#8230;) just starts at the current prime number and iterate upward until it finds the next prime number.  (search-for-factors &#8230;) does the actual searching for prime factors.</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>smallest-divisor n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>find-divisor n 2<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>divides? a b<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>remainder b a<span class="br0">&#41;</span> 0<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>square n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* n n<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>next-divisor n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">=</span> n 2<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; 3
&nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>+ n 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>find-divisor n test-divisor<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">&gt;</span> <span class="br0">&#40;</span>square test-divisor<span class="br0">&#41;</span> n<span class="br0">&#41;</span> n<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>divides? test-divisor n<span class="br0">&#41;</span> test-divisor<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>find-divisor n <span class="br0">&#40;</span>next-divisor test-divisor<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>prime? n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="sy0">=</span> n <span class="br0">&#40;</span>smallest-divisor n<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>next-prime n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">let</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>m <span class="br0">&#40;</span>+ n 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span>prime? m<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>next-prime m<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>search-for-factors n factor<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>/ n factor<span class="br0">&#41;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>display factor<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>newline<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>divides? factor n<span class="br0">&#41;</span> <span class="br0">&#40;</span>display factor<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>newline<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>search-for-factors <span class="br0">&#40;</span>/ n factor<span class="br0">&#41;</span> factor<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>search-for-factors n <span class="br0">&#40;</span>next-prime factor<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>search-for-factors <span class="nu0">600851475143</span> <span class="nu0">2</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/project-euler-problem-3-in-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SICP Section 1.2.4</title>
		<link>http://mbowcock.com/notebook/sicp-1-2/</link>
		<comments>http://mbowcock.com/notebook/sicp-1-2/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 02:24:58 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[sicp]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=106</guid>
		<description><![CDATA[The code below is exercises 1.16 and 1.17. I&#8217;ll finish up 1.18 and 1.19 some time in the future. I&#8217;ve created a repository on github to store the code I write while working through SICP &#8211; if you&#8217;re interested it can be found at http://github.com/mbowcock/SICP. Exercise 1.16 - &#40;define &#40;square n&#41; &#160; &#40;* n n&#41;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>The code below is exercises 1.16 and 1.17.  I&#8217;ll finish up 1.18 and 1.19 some time in the future.  I&#8217;ve created a repository on github to store the code I write while working through SICP &#8211; if you&#8217;re interested it can be found at <br /><a href="http://github.com/mbowcock/SICP">http://github.com/mbowcock/SICP</a>.</p>
<p>Exercise 1.16 -</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>square n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* n n<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>fast-expt-iter b n a<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> n <span class="nu0">0</span><span class="br0">&#41;</span> a<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>even? n<span class="br0">&#41;</span> <span class="br0">&#40;</span>fast-expt-iter b <span class="br0">&#40;</span>- n <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* a <span class="br0">&#40;</span>square b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>fast-expt-iter b <span class="br0">&#40;</span>- n <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* a b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>fast-expt-new b n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>fast-expt-iter b n <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>Exercise 1.17 &#8211; </p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>double n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* n 2<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>halve n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>/ n 2<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>*<span class="sy0">.</span> a b<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> b <span class="nu0">0</span><span class="br0">&#41;</span> <span class="nu0">0</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>even? b<span class="br0">&#41;</span> <span class="br0">&#40;</span>*<span class="sy0">.</span> <span class="br0">&#40;</span>double a<span class="br0">&#41;</span> <span class="br0">&#40;</span>halve b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>+ a <span class="br0">&#40;</span>*<span class="sy0">.</span> a <span class="br0">&#40;</span>- b <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mbowcock.com/notebook/sicp-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.610 seconds --><!-- Cached page served by WP-Cache -->

