<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
  <title>sjs - geeky ramblings</title>
  <id>tag:sami.samhuri.net,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  
  <link href="http://sami.samhuri.net/" rel="alternate" type="text/html" />
  <updated>2008-03-04T00:25:26Z</updated>
  <link rel="self" href="http://feeds.feedburner.com/sjs" type="application/atom+xml" /><entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2008-03-04:723</id>
    <published>2008-03-04T00:24:00Z</published>
    <updated>2008-03-04T00:25:26Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/_fmzzNc5_OY/project-euler-code-repo-in-arc" rel="alternate" type="text/html" />
    <title>Project Euler code repo in Arc</title>
<content type="html">
            &lt;p&gt;Release early and often. This is a code repo web app for solutions to &lt;a href="http://projecteuler.net"&gt;Project Euler&lt;/a&gt; problems.  You can only see your own solutions so it’s not that exciting yet (but it scratches my itch… once it highlights syntax).  You can &lt;a href="http://nofxwiki.net:3141/euler"&gt;try it out&lt;/a&gt; or &lt;a href="http://samhuri.net/euler.tgz"&gt;download the source&lt;/a&gt;. You’ll need an up-to-date copy of &lt;a href="http://arcfn.com/2008/02/git-and-anarki-arc-repository-brief.html"&gt;Anarki&lt;/a&gt; to untar the source in.  Just run &lt;strong&gt;arc.sh&lt;/strong&gt; then enter this at the &lt;span class="caps"&gt;REPL&lt;/span&gt;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;arc&amp;gt; (load "euler.arc")
arc&amp;gt; (esv)
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;That will setup the web server on port 3141.  If you want a different port then run &lt;code&gt;(esv 25)&lt;/code&gt; (just to mess with ‘em).&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/_fmzzNc5_OY" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2008/3/4/project-euler-code-repo-in-arc</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2008-02-19:721</id>
    <published>2008-02-19T19:26:00Z</published>
    <updated>2008-02-19T21:21:34Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/oag-ymFnAA8/thoughts-on-arc" rel="alternate" type="text/html" />
    <title>Thoughts on Arc</title>
<content type="html">
            &lt;p&gt;&lt;em&gt;NB: This is just a braindump.  There's nothing profound or particularly insightful in this post.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You may have heard that &lt;a href="http://www.paulgraham.com"&gt;Paul Graham&lt;/a&gt; recently released his pet dialect of Lisp: &lt;a href="http://arclanguage.org"&gt;Arc&lt;/a&gt;.  It's a relatively small language consisting of just 4500 lines of code.  In just under &lt;a href="http://arclanguage.com/install"&gt;1200 lines&lt;/a&gt; of &lt;a href="http://www.plt-scheme.org/"&gt;PLT Scheme&lt;/a&gt; the core of Arc is defined.  The rest of the language is written in Arc itself.  The heart of that is a file arc.arc, weighing in at 1500 lines.  The remaining 1000-1300 lines are spread between libraries, mainly for writing web apps: html.arc, srv.arc, app.arc, and a few others.&lt;/p&gt;

&lt;p&gt;I'm not going to go into great detail, but Arc is a fun language.  You can read all the code in one or two sittings and start hacking on it in no time.  The code is simple where simple gets the job done and if you can follow &lt;a href="http://mitpress.mit.edu/sicp/"&gt;SICP&lt;/a&gt; then you should understand it with relative ease (assuming you're somewhat familiar with Lisp).&lt;/p&gt;

&lt;h3&gt;Parsing, Markdown&lt;/h3&gt;

&lt;p&gt;I'm writing a simple parser combinators library (loosely modeled on &lt;a href="http://legacy.cs.uu.nl/daan/parsec.html"&gt;Parsec&lt;/a&gt;) in order to write a nice Markdown implementation.  Overkill?  Indeed.  Parsec is a wonderful library and it is written beautifully.  If I end up with something 1/2 as powerful and 1/10th as beautiful I'll be pleased.  This was all in order to beef up the version of Markdown bundled with Arc so I could write a basic wiki.  I've been &lt;a href="http://arclanguage.org/item?id=1456"&gt;beaten&lt;/a&gt; to the punch, &lt;a href="http://arclanguage.org/item?id=2037"&gt;twice&lt;/a&gt;!  Perhaps I'll retrofit Markdown onto jgc's wiki once I get something decent finished.&lt;/p&gt;

&lt;h3&gt;Brevity and Innovation&lt;/h3&gt;

&lt;p&gt;The brevity of Arc is both a blessing and a curse.  On the one hand it makes for a very hacking-friendly language.  It's easy/fun to try things in the REPL and write throwaway code for learning purposes.  Paul's wanton removal of extraneous parentheses is a great boon.  On the flip side Arc code can be a little cryptic at a first glance.  While reading code there's a small period of time where you have to figure out what the short names are and what they do, but because the language is so small it's utterly trivial to grep or read the source and find out exactly how everything fits together and get the context you need.  Once you're familiar with the domain then the terse names not only make sense, but they make the interesting parts of the code stand out more.  I want to emphasize the pleasure of using Arc to learn.  I think that Paul is on to something with the general brevity and simple nature of Arc.&lt;/p&gt;

&lt;p&gt;Some interesting ways that Paul has reduced code is by introducing new intra-symbol operators.  Besides the usual backquote/quasiquote and comma/unquote translations, several other special characters are translated when they appear within/around symbols.&lt;/p&gt;

&lt;p&gt;There is the colon/compose operator that reduces code such as: &lt;code&gt;(sym (string "pre-" something "-suffix"))&lt;/code&gt; to &lt;code&gt;(sym:string "pre-" something "-suffix")&lt;/code&gt;.  It can help with car/cdr chains without defining monstrosities such as &lt;code&gt;cadadr&lt;/code&gt;, though whether &lt;code&gt;(cadadr ...)&lt;/code&gt; is better than &lt;code&gt;(cadr:cadr ...)&lt;/code&gt; is better than &lt;code&gt;(car (cdr (car (cdr ...))))&lt;/code&gt; is up to you.&lt;/p&gt;

&lt;p&gt;My favourite is the tilde to mean logical negation: &lt;code&gt;no&lt;/code&gt; in Arc, &lt;code&gt;not&lt;/code&gt; in most other languages.  It doesn't shorten code much but it helps with parens.  &lt;code&gt;(if (no (empty str)) ...)&lt;/code&gt; becomes &lt;code&gt;(if (~empty str) ...)&lt;/code&gt;.  Not much to be said about it, but it reads very nicely in code.&lt;/p&gt;

&lt;p&gt;Some newer ones are the dot and exclamation point to aide in the composition of functions requiring arguments.  I won't go into detail as their use is trivial.  If you're interested read &lt;a href="http://arclanguage.org/item?id=2166"&gt;Paul's explanation&lt;/a&gt; of them.&lt;/p&gt;

&lt;h3&gt;Web programming&lt;/h3&gt;

&lt;p&gt;Paul has touted Arc as a good web programming language, most notably in his &lt;a href="http://www.paulgraham.com/arcchallenge.html"&gt;Arc Challenge&lt;/a&gt; that caused a minor stir in a few blogs and on Reddit.  I'm writing a small web app for myself in Arc.  I may host it somewhere public when it's useable.  It's a somewhat &lt;a href="http://pastie.caboo.se/"&gt;pastie&lt;/a&gt;-like app specifically for storing/sharing solutions to problems over at &lt;a href="http://projecteuler.net"&gt;Project Euler&lt;/a&gt;, which I recently started tackling.  "What's wrong with saving the code on your hard disk without a web app?", you ask? It doesn't give me an excuse to try Arc as a web language. ;-)&lt;/p&gt;

&lt;p&gt;So far I find that Arc is quite a nice web language.  With the handy HTML tag library you can generate 90s-style, quirks-mode-compliant tag soup in a blink.  I haven't had trouble producing HTML 4.01 (strict) that validates.  There's no need for a template language or partials (à la Rails), you just compose tags-as-sexps using Arc itself.  This turns out to be quite elegant, even if somewhat reminiscent of my first forays into web programming with PHP.  I don't feel as if I'm writing a web app so much as I'm writing an app that happens to present its UI in HTML.  &lt;em&gt;(I'm reminded a little of &lt;a href="http://webpy.org/"&gt;web.py&lt;/a&gt;, which I enjoy as the antithesis of Rails.)&lt;/em&gt;  I suppose it takes some discipline to separate your logic &amp;amp; design when everything's mixed in the same file, but there's nothing stopping you from separating the logic and views into their own files if you really prefer to do it that way.&lt;/p&gt;

&lt;p&gt;There's no distinction between GET and POST params.  This surprised me, but then I thought about it and it's not a big deal for most apps, imo.&lt;/p&gt;

&lt;p&gt;The app I'm writing is standard CRUD stuff so I haven't done anything cool using continuations yet.  I plan to use call/cc for backtracking in my parser, but I'm still a ways from implementing that kind of functionality!&lt;/p&gt;

&lt;h3&gt;Non-conclusion&lt;/h3&gt;

&lt;p&gt;I feel as though I should have a conclusion, but I don't.  I've only been using Arc for a short time.  It feels nice.  I think Paul is doing a good job on the design by keeping it small, compact, and simple.  Seeing as it's still in its infancy it's just a toy for me, but a toy with some decent potential.  And hopefully an impact on other Lisps.  Common Lisp may have industrial implementations and a 1500 page spec, but Arc is more fun and hackable.  More so than Scheme, too.  I think Arc has out-Schemed Scheme.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/oag-ymFnAA8" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2008/2/19/thoughts-on-arc</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2008-01-08:706</id>
    <published>2008-01-08T01:42:00Z</published>
    <updated>2008-01-08T01:50:01Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/1aXR8197Wr4/random-pet-peeve-of-the-day" rel="alternate" type="text/html" />
    <title>Random pet peeve of the day</title>
<content type="html">
            &lt;p&gt;So long since my last post, and all I’m going to do is complain. ;-)  Seriously though, if you have a website and the content on said site is dated then please – for the love of our almighty saviour, the &lt;a href="http://www.venganza.org/about"&gt;Flying Spaghetti Monster&lt;/a&gt; – &lt;em&gt;put the date at the &lt;strong&gt;top&lt;/strong&gt; of the page&lt;/em&gt;.  Don’t make me scroll down to the end of the article just to see how relevant it is or just to give me some context. Not to mention that I always end up doing a “Where &lt;em&gt;is&lt;/em&gt; the end? Oh crap, I passed it and now I’m in the comments, blargh!”&lt;/p&gt;


	&lt;p&gt;I’m looking at Lifehacker since they’re the most recent offender I’ve come across, but they are definitely not the only ones guilty of this.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/1aXR8197Wr4" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2008/1/8/random-pet-peeve-of-the-day</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-10-30:316</id>
    <published>2007-10-30T04:14:00Z</published>
    <updated>2007-12-21T13:34:54Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/e-1nDI3RZ28/gtkpod-in-gutsy-got-you-groaning" rel="alternate" type="text/html" />
    <title>Gtkpod in Gutsy Got You Groaning?</title>
<content type="html">
            &lt;p&gt;I recently upgraded the &lt;a href="http://www.ubuntu.com"&gt;Ubuntu&lt;/a&gt; installation on my workstation from Feisty Fawn to Gutsy Gibbon and for the most part I am happy with the changes.  One thing I don’t care much for is the fact that gtkpod-aac is a sham.  Ubuntu provides the gtkpod-aac package for one to transfer aac files, and thus mp4 files with aac audio tracks, to their iPod.  The version in the Gutsy repos is broken.  This shows a weakness in Ubuntu, and though it’s rather small it is one that will piss off a lot of people who expect things to just work.  The kind of people who would buy an iPod.  The kind of people who use Linux.  The kind of Linux users that use Ubuntu.  The kicker is that &lt;a href="https://bugs.launchpad.net/ubuntu/+source/gtkpod-aac/+bug/135178/comments/6"&gt;it doesn’t look like&lt;/a&gt; they will ship a working version of gtkpod-aac for Gutsy at all.  I know it’s only 6 months but that seems like an eternity when you have the same old crap to watch on your iPod for that long.&lt;/p&gt;


	&lt;p&gt;All is not lost.  A kind soul left &lt;a href="https://bugs.launchpad.net/ubuntu/+source/gtkpod-aac/+bug/135178/comments/7"&gt;a helpful comment&lt;/a&gt; on the &lt;a href="https://bugs.launchpad.net/ubuntu/+source/gtkpod-aac/+bug/135178"&gt;bug report&lt;/a&gt; explaining how he got it to work.  It’s a pretty simple fix.  Just &lt;a href="http://www.google.ca/search?q=libmpeg4ip"&gt;google for libmpeg4ip&lt;/a&gt; and find a &lt;a href="http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/"&gt;Debian repo that has the following packages&lt;/a&gt; for your architecture:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;libmpeg4ip-0&lt;/li&gt;
		&lt;li&gt;libmpeg4ip-dev&lt;/li&gt;
		&lt;li&gt;libmp4v2-0&lt;/li&gt;
		&lt;li&gt;libmp4v2-dev&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Download those 4 .deb files and install them.  You can ignore any advise to use an older version in the official repo.  Once you have those installed, download and build the latest version of gtkpod from their &lt;a href="http://sourceforge.net/svn/?group_id=67873"&gt;Subversion repo&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Now that you know what to do I’ll give you what you probably wanted at the beginning.  As long as you have wget, subversion, and use a Bourne-like shell this should work for you.&lt;/p&gt;


	&lt;p&gt;&amp;darr; &lt;a href="http://sami.samhuri.net/assets/2007/10/30/gtkpod-aac-fix.sh"&gt;gtkpod-aac-fix.sh&lt;/a&gt;&lt;/p&gt;


&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;mkdir /tmp/gtkpod-fix&lt;tt&gt;
&lt;/tt&gt;cd /tmp/gtkpod-fix&lt;tt&gt;
&lt;/tt&gt;wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmp4v2-0_1.5.0.1-0.3_amd64.deb&lt;tt&gt;
&lt;/tt&gt;wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmp4v2-dev_1.5.0.1-0.3_amd64.deb&lt;tt&gt;
&lt;/tt&gt;wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmpeg4ip-0_1.5.0.1-0.3_amd64.deb&lt;tt&gt;
&lt;/tt&gt;wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmpeg4ip-dev_1.5.0.1-0.3_amd64.deb&lt;tt&gt;
&lt;/tt&gt;for f in *.deb; do sudo gdebi -n &amp;quot;$f&amp;quot;; done&lt;tt&gt;
&lt;/tt&gt;svn co https://gtkpod.svn.sourceforge.net/svnroot/gtkpod/gtkpod/trunk gtkpod&lt;tt&gt;
&lt;/tt&gt;cd gtkpod&lt;tt&gt;
&lt;/tt&gt;./autogen.sh --with-mp4v2 &amp;amp;&amp;amp; make &amp;amp;&amp;amp; sudo make install&lt;tt&gt;
&lt;/tt&gt;cd&lt;tt&gt;
&lt;/tt&gt;rm -rf /tmp/gtkpod-fix&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/e-1nDI3RZ28" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/10/30/gtkpod-in-gutsy-got-you-groaning</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-09-26:312</id>
    <published>2007-09-26T17:34:00Z</published>
    <updated>2007-09-26T18:15:23Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/69InzIqxZNQ/python-and-ruby-brain-dump" rel="alternate" type="text/html" />
    <title>Python and Ruby brain dump</title>
<content type="html">
            &lt;p&gt;It turns out that &lt;a href="http://dev.laptop.org/git?p=security;a=blob;f=bitfrost.txt"&gt;Python is the language of choice on the &lt;span class="caps"&gt;OLPC&lt;/span&gt;&lt;/a&gt;, both for implementing applications and exposing to the users.  There is a view source key available.  I think Python is a great choice.&lt;/p&gt;


	&lt;p&gt;I’ve been using Ruby almost exclusively for over a year but the last week I’ve been doing a personal project in Python using &lt;a href="https://storm.canonical.com/"&gt;Storm&lt;/a&gt; (which is pretty nice btw) and &lt;a href="http://excess.org/urwid/"&gt;urwid&lt;/a&gt;.  I’m remembering why I liked Python when I first learned it a few years ago.  It may not be as elegant as Ruby, conceptually, but it sure is fun to code in.  It really is executable pseudo-code for the most part.&lt;/p&gt;


	&lt;p&gt;I’m tripping up by typing &lt;code&gt;obj.setattr^W^Wsetattr(obj&lt;/code&gt; and &lt;code&gt;def self.foo^W^Wfoo(self&lt;/code&gt; but other than that I haven’t had trouble switching back into Python.  I enjoy omitting &lt;code&gt;end&lt;/code&gt; statements.  I enjoy Python’s lack of curly braces, apart from literal dicts.  I hate the fact that in Emacs, in python-mode, &lt;code&gt;indent-region&lt;/code&gt; only seems to piss me off (or &lt;code&gt;indent-*&lt;/code&gt; really, anything except &lt;span class="caps"&gt;TAB&lt;/span&gt;).  I really like list comprehensions.&lt;/p&gt;


	&lt;p&gt;The two languages are so similar that at a glance you may think there are only shallow differences between the languages.  People are always busy arguing about the boring things that every language can do (web frameworks anyone?) while ignoring the interesting differences between the languages and their corresponding ecosystems.&lt;/p&gt;


	&lt;p&gt;Python has more libraries available as it’s the more popular language.  The nature of software written in the languages is different though as the languages themselves are quite different.&lt;/p&gt;


	&lt;p&gt;Ruby has some Perl-ish features that make it a good sysadmin scripting language, hence we see nice tools such as &lt;a href="http://www.capify.org/"&gt;Capistrano&lt;/a&gt; and &lt;a href="http://god.rubyforge.org/"&gt;god&lt;/a&gt; written in Ruby and used by projects written in other languages.&lt;/p&gt;


	&lt;p&gt;Python is faster than Ruby so it is open to classes of software that would be cumbersome in Ruby.  Source control, for example.  You can write a slow &lt;span class="caps"&gt;SCM&lt;/span&gt; in Python though, as &lt;a href="http://bazaar-vcs.org/"&gt;Bazaar&lt;/a&gt; demonstrates.  You could probably write a passable one in Ruby as well.  If it didn’t quite perform well enough right now it should fare better in a year’s time.&lt;/p&gt;


	&lt;p&gt;I still think that my overall joy is greater when using Ruby, but if Ruby isn’t the right tool for the job I’ll probably look to Python next (unless some feature of the problem indicates something else would be more appropriate).  The reason I chose Python for my current project is because of libs like urwid and I needed an excuse to try out Storm and brush up on my Python. ;-)&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/69InzIqxZNQ" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/9/26/python-and-ruby-brain-dump</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-09-25:308</id>
    <published>2007-09-25T16:59:00Z</published>
    <updated>2007-09-25T17:01:26Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/k7eAbWeRcXk/learning-lisp-read-pcl" rel="alternate" type="text/html" />
    <title>Learning Lisp? Read PCL</title>
<content type="html">
            &lt;p&gt;Yes, it’s a book.  But it’s so well written you should breeze through it as if it were a &lt;a href="http://www.gigamonkeys.com/book/"&gt;Lisp tutorial&lt;/a&gt;!&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/k7eAbWeRcXk" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/9/25/learning-lisp-read-pcl</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-26:248</id>
    <published>2007-08-26T19:35:00Z</published>
    <updated>2007-08-26T22:34:11Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/OXD-8Bh0WeI/captivating-little-creatures" rel="alternate" type="text/html" />
    <title>Captivating little creatures</title>
<content type="html">
            &lt;p&gt;Someone posted this JavaScript implementation of an old gem on Reddit, &lt;a href="http://www.elizium.nu/scripts/lemmings/"&gt;Lemmings&lt;/a&gt;! There goes my Sunday! :)&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/OXD-8Bh0WeI" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/26/captivating-little-creatures</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-22:239</id>
    <published>2007-08-22T01:20:00Z</published>
    <updated>2007-08-22T01:22:29Z</updated>
    <category term="Emacs" />
    <link href="http://feedproxy.google.com/~r/sjs/~3/PEqUCajm03s/cheat-productively-in-emacs" rel="alternate" type="text/html" />
    <title>Cheat productively in Emacs</title>
<content type="html">
            &lt;p&gt;By now you may have heard about &lt;a href="http://cheat.errtheblog.com"&gt;cheat&lt;/a&gt;, the command line cheat sheet collection that’s completely open to editing, wiki style.  A couple of weeks ago I posted &lt;a href="http://sami.samhuri.net/2007/8/10/cheat-from-emacs"&gt;cheat.el&lt;/a&gt; which allows one to cheat from within Emacs.  There’s an update.  However, before I get to cheat.el there’s a small detour.&lt;/p&gt;


	&lt;p&gt;Cheat is not just about Ruby!  A few examples of cheats available are:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;bash and zsh&lt;/li&gt;
		&lt;li&gt;$EDITOR (if you happen to like e, TextMate, vi, emacs, RadRails, ...)&lt;/li&gt;
		&lt;li&gt;&lt;span class="caps"&gt;GNU&lt;/span&gt; screen&lt;/li&gt;
		&lt;li&gt;Version control (darcs, svn, git)&lt;/li&gt;
		&lt;li&gt;Firebug&lt;/li&gt;
		&lt;li&gt;Markdown and Textile&lt;/li&gt;
		&lt;li&gt;Oracle and MySQL&lt;/li&gt;
		&lt;li&gt;Regular expressions&lt;/li&gt;
		&lt;li&gt;and of course Ruby, Rails, Capistrano, etc.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;As of today, Aug-21 2007, the count is at &lt;strong&gt;166 cheat sheets&lt;/strong&gt; so there’s probably something there that you’ll want to look up from the command line or Emacs sometime.  That’s enough stroking cheat’s ego, but there seems to be a notion that cheat is only for Ruby stuff and that’s really not the case.&lt;/p&gt;


	&lt;p&gt;So what’s new in this version of cheat.el?  &lt;strong&gt;Completion!&lt;/strong&gt;  The only thing that bothered me about cheating in Emacs was the lack of completion.  It now has completion, thus it is now perfect. :)  In all likeliness this won’t be the last release, but I can’t really foresee adding anything else to it in the near future.  Enjoy!&lt;/p&gt;


	&lt;p&gt;Download it now: &lt;a href="http://sami.samhuri.net/assets/2007/8/10/cheat.el"&gt;cheat.el&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;For any newcomers, just drop this into &lt;code&gt;~/.emacs.d&lt;/code&gt;, &lt;code&gt;~/.elisp&lt;/code&gt;, or any directory in your &lt;code&gt;load-path&lt;/code&gt; and then &lt;code&gt;(require 'cheat)&lt;/code&gt;.  For more info check the &lt;a href="http://sami.samhuri.net/2007/8/10/cheat-from-emacs"&gt;original article&lt;/a&gt; for a rundown on the cheat commands.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/PEqUCajm03s" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/22/cheat-productively-in-emacs</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-20:233</id>
    <published>2007-08-20T05:17:00Z</published>
    <updated>2007-08-20T05:49:20Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/_Evyghu0lPM/catch-compiler-errors-at-runtime" rel="alternate" type="text/html" />
    <title>Catch compiler errors at runtime</title>
<content type="html">
            &lt;p&gt;While coding just now I had a small epiphany about Ruby.  Though Ruby is highly dynamic and compiled at runtime, that doesn’t preclude one catching some mistakes at compile time.  I’m not talking about mere syntax errors or anything either.  The only proviso to catching mistakes at compile time is that you must have a decent chunk of code executed during compilation.  One benefit of Ruby’s blurring of compile time and runtime is that you can run real code at compile time.  This is largely how metaprogramming tricks are pulled off elegantly and with ease in projects such as Rails.&lt;/p&gt;


	&lt;p&gt;Sure you won’t get all the benefits of a strictly and/or statically typed compiler, but you can get some of them.  If you have a library that makes substantial use of executing code at compile time then the mere act of loading your library causes your code to run, thus it compiles.  If you &lt;code&gt;require&lt;/code&gt; your lib and get &lt;code&gt;true&lt;/code&gt; back then you know the code that bootstraps the runtime code is at least partially correct.&lt;/p&gt;


	&lt;p&gt;Compile time is runtime.  Runtime is compile time.  Just because you have to run the code to compile it doesn’t mean you can’t catch a good chunk of compiler errors before you send out your code.  Tests will always be there for the rest of your mistakes, but if you can pull work into compile time then Ruby’s compiler can augment your regular testing practices.&lt;/p&gt;


	&lt;p&gt;I admit that this is of limited use most of the time, but let it not be said that you can’t catch any errors with your compiler just because you have to run your code to compile it.  With Ruby the more meta you get the more the compiler rewards you.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;[Of course this is true of languages such as Common Lisp too, which make available the full programming language at compile time. I just happened to be using Ruby when I realized this.]&lt;/em&gt;&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/_Evyghu0lPM" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/20/catch-compiler-errors-at-runtime</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-11:223</id>
    <published>2007-08-11T19:11:00Z</published>
    <updated>2007-08-11T19:30:12Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/HdGX4ENcyZc/opera-is-pretty-slick" rel="alternate" type="text/html" />
    <title>Opera is pretty slick</title>
<content type="html">
            &lt;p&gt;Though I usually prefer free software, I don’t have any problems using proprietary stuff if I think it’s good.  I had Firefox open for a couple of days and noticed that it was using 700M of memory.  That’s not a problem at all since I have 4G but it’s also a lot of &lt;span class="caps"&gt;RAM&lt;/span&gt; to be in use for just one window with one tab open.  The fact that Firefox gets sluggish after some time and needs to be restarted tells me that this isn’t expected behaviour and is likely not due to caching for quick back/forward or whatever they claim is taking up the leaked memory.&lt;/p&gt;


	&lt;p&gt;Konqueror is ok but I’m not a huge fan of it, partly due to its kitchen-sink browser/file manager hybrid design.  &lt;span class="caps"&gt;IMO&lt;/span&gt; the &lt;span class="caps"&gt;KDE&lt;/span&gt; folks should break out the file manager part, but I digress.  I can’t really put my finger on anything specific I dislike about Konqueror, it’s just not for me.  To my dismay it seems to be the snappiest browser on Linux.&lt;/p&gt;


	&lt;p&gt;The only other decent browser I know of (for Linux) is Opera so I found some quick instructions on the Ubuntu forums and shoehorned the x86 build of it into my amd64 installation.  Everything went well, Flash works and all that stuff.  Opera is not nearly as snappy as I like but it is still fairly pleasant to use, once you find a skin that fits into your desktop.  For the record Firefox isn’t snappy enough either.  Apart from AdBlock I don’t miss many extensions for every day browsing.&lt;/p&gt;


	&lt;p&gt;I’m not sure if I’m going to stick with it yet but I’ve been using it for 2 days and haven’t really missed Firefox at all.  Of course as soon as I do any development I need Firefox for Firebug and the Web Developer extension and such.  I’ve yet to investigate development tools on Opera.  I’m comfortable developing in Firefox already so why switch?&lt;/p&gt;


	&lt;p&gt;Man am I glad we’re not in a Netscape/IE world anymore!  If I open up my MacBook I can choose from at least 2 other browsers for every day browsing (Camino, Safari).&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/HdGX4ENcyZc" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/11/opera-is-pretty-slick</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-10:217</id>
    <published>2007-08-10T08:56:00Z</published>
    <updated>2007-08-22T01:30:22Z</updated>
    <category term="Emacs" />
    <link href="http://feedproxy.google.com/~r/sjs/~3/sJ-xv3qyllc/cheat-from-emacs" rel="alternate" type="text/html" />
    <title>Cheat from Emacs</title>
<content type="html">
            &lt;p&gt;&lt;em&gt;Update: I had inadvertently used &lt;code&gt;string-join&lt;/code&gt;, a function provided by something in my ~/.emacs.d. The script has been updated to work with a vanilla Emacs (23, but should work with 22 as well).&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;Update #2 [2007.08.10]: Editing cheats and diffs have been implemented.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;Update #3 [2007.08.21]: I &lt;a href="http://sami.samhuri.net/2007/8/21/cheat-productively-in-emacs"&gt;added completion&lt;/a&gt; to cheat.el. The file linked on this page is still the latest version.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;We all know and love &lt;a href="http://cheat.errtheblog.com"&gt;cheat&lt;/a&gt;.  Now you can cheat without leaving Emacs (and without using a shell in Emacs).&lt;/p&gt;


	&lt;p&gt;Just save &lt;a href="http://sami.samhuri.net/assets/2007/8/10/cheat.el"&gt;cheat.el&lt;/a&gt; in ~/.emacs.d and then &lt;code&gt;(require 'cheat)&lt;/code&gt; in your ~/.emacs.  I also bind &lt;code&gt;C-z C-c&lt;/code&gt; to &lt;code&gt;cheat&lt;/code&gt;, you may want to do something similar.&lt;/p&gt;


	&lt;p&gt;&lt;del&gt;You can’t do everything you can do with cheat on the command line yet&lt;/del&gt;, and for most of the commands the cheat command itself is used. &lt;em&gt;Now you can do everything the command line client does from within Emacs, though you may need to revert to using &lt;code&gt;cheat-command&lt;/code&gt; (described below).&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;Here’s the rundown:&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;Any time you enter a cheat name there are both completion and a cheat-specific history available.  Unless you are adding a new cheat.  In that case you should use a new, unique name (duh).&lt;/em&gt;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;cheat&lt;/code&gt; – Lookup a cheat sheet interactively (&lt;code&gt;cheat &amp;lt;name&amp;gt;&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-sheets&lt;/code&gt; – List all cheat sheets (&lt;code&gt;cheat sheets&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-recent&lt;/code&gt; – List recently added cheat sheets (&lt;code&gt;cheat recent&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-versions&lt;/code&gt; – List versions of a cheat sheet interactively (&lt;code&gt;cheat &amp;lt;name&amp;gt; --versions&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-clear-cache&lt;/code&gt; – Clear all cached sheets.&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-add-current-buffer&lt;/code&gt; – Add a new cheat using the specified name and the contents of the current buffer as the body. (&lt;code&gt;cheat &amp;lt;name&amp;gt; --add&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-edit&lt;/code&gt; – Retrieve a fresh copy of the named cheat and display the body in a buffer for editing.&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-save-current-buffer&lt;/code&gt; – Save the current cheat buffer, which should be named &lt;code&gt;*cheat-&amp;lt;name&amp;gt;*&lt;/code&gt;.&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-diff&lt;/code&gt; – Show the diff between the current version and the given version of the named cheat. If the version given is of the form &lt;em&gt;m:n&lt;/em&gt; then show the diff between versions &lt;em&gt;m&lt;/em&gt; and &lt;em&gt;n&lt;/em&gt;. (&lt;code&gt;cheat &amp;lt;name&amp;gt; --diff &amp;lt;version&amp;gt;&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;&lt;code&gt;cheat-command&lt;/code&gt; – Pass any arguments you want to cheat interactively.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;em&gt;(Added)&lt;/em&gt; &lt;del&gt;I may add support for &lt;code&gt;--diff&lt;/code&gt; and &lt;code&gt;--edit&lt;/code&gt; in the future.&lt;/del&gt;&lt;/p&gt;


	&lt;p&gt;Please do send me your patches so everyone can benefit from them.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/sJ-xv3qyllc" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/10/cheat-from-emacs</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-09:214</id>
    <published>2007-08-09T17:17:00Z</published>
    <updated>2007-08-09T17:32:15Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/TlO6XqTMhug/snap-crunchle-pop" rel="alternate" type="text/html" />
    <title>Snap, crunchle, pop</title>
<content type="html">
            &lt;p&gt;I think that every now and then we need to be reminded of the frail nature of our human bodies.  Yesterday morning as I walked to my kitchen I was turning right by pivoting on my right foot when my 24 years of walking experience suddenly failed me.  I clearly did something wrong, as I heard a crunching pop or two in my right ankle and went down.  Luckily it’s just a sprain but my foot is fairly bruised and still sore today.  I’m trying to follow the &lt;a href="http://orthopedics.about.com/cs/sprainsstrains/a/sprain_4.htm"&gt;&lt;span class="caps"&gt;RICE&lt;/span&gt;&lt;/a&gt; method for recuperating but one can only lay down for so long before having to eat, work, use the bathroom, etc.  Thank goodness I don’t work on my feet or I’d be out of commission.  If it still hurts next week I’m going to see a doctor but till then I’m trying not to leave my house.  The idea of hopping and hobbling to a bus to go to a doctor does not thrill me in the slightest.&lt;/p&gt;


	&lt;p&gt;Oh, if you find yourself in a bind an upside down hockey stick is a decent makeshift crutch.  You’ll need 2 hands to operate the thing though.&lt;/p&gt;


	&lt;p&gt;At the opposite end of the spectrum there are times when we seem to be amazingly resilient creatures.  Check out a documentary called &lt;em&gt;“101 Things Removed from the Human Head”&lt;/em&gt; if you can find it anywhere.  One of those things was a boat anchor, I kid you not.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/TlO6XqTMhug" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/9/snap-crunchle-pop</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-08-02:210</id>
    <published>2007-08-02T23:59:00Z</published>
    <updated>2007-12-21T13:34:22Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/PhpQUlcZyYM/elschemo-boolean-logic-and-branching" rel="alternate" type="text/html" />
    <title>ElSchemo: Boolean logic and branching</title>
<summary type="html">&lt;p&gt;Well it has been a while since my last post.  I’ll try not to do that
frequently.  Anyhow, on to the good stuff.&lt;/p&gt;


	&lt;p&gt;I’ve been developing a Scheme
interpreter in Haskell called
&lt;a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo"&gt;ElSchemo&lt;/a&gt;.
It started from &lt;a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html"&gt;Jonathan’s excellent Haskell
tutorial&lt;/a&gt;
which I followed in order to learn both Haskell and Scheme.  Basically
that means the code here is for me to get some feedback as much
as to show others how to do this kind of stuff.  This may not be too
interesting if you haven’t at least browsed the tutorial.&lt;/p&gt;


	&lt;p&gt;I’m going to cover 3 new special forms: &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, and &lt;code&gt;cond&lt;/code&gt;.  I
promised to cover the &lt;code&gt;let&lt;/code&gt; family of special forms this time around
but methinks this is long enough as it is.  My sincere apologies if
you’ve been waiting for those.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Well it has been a while since my last post.  I’ll try not to do that
frequently.  Anyhow, on to the good stuff.&lt;/p&gt;


	&lt;p&gt;I’ve been developing a Scheme
interpreter in Haskell called
&lt;a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo"&gt;ElSchemo&lt;/a&gt;.
It started from &lt;a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html"&gt;Jonathan’s excellent Haskell
tutorial&lt;/a&gt;
which I followed in order to learn both Haskell and Scheme.  Basically
that means the code here is for me to get some feedback as much
as to show others how to do this kind of stuff.  This may not be too
interesting if you haven’t at least browsed the tutorial.&lt;/p&gt;


	&lt;p&gt;I’m going to cover 3 new special forms: &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, and &lt;code&gt;cond&lt;/code&gt;.  I
promised to cover the &lt;code&gt;let&lt;/code&gt; family of special forms this time around
but methinks this is long enough as it is.  My sincere apologies if
you’ve been waiting for those.&lt;/p&gt;
&lt;p&gt;I’ve been developing a Scheme
interpreter in Haskell called
&lt;a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo"&gt;ElSchemo&lt;/a&gt;.
It started from &lt;a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html"&gt;Jonathan’s excellent Haskell
tutorial&lt;/a&gt;
which I followed in order to learn both Haskell and Scheme.  Basically
that means the code here is for me to get some feedback as much
as to show others how to do this kind of stuff.  This may not be too
interesting if you haven’t at least browsed the tutorial.&lt;/p&gt;


	&lt;p&gt;I’m going to cover 3 new special forms: &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, and &lt;code&gt;cond&lt;/code&gt;.  I
promised to cover the &lt;code&gt;let&lt;/code&gt; family of special forms this time around
but methinks this is long enough as it is.  My sincere apologies if
you’ve been waiting for those.&lt;/p&gt;


	&lt;h2&gt;Short-circuiting Boolean logic&lt;/h2&gt;


	&lt;p&gt;Two functions from the tutorial which may irk you immediately are
&lt;code&gt;and&lt;/code&gt; and &lt;code&gt;or&lt;/code&gt;, defined in Scheme in the given standard library.  If
your code is free of side-effects then it may not bother you so
much.  It bothered me.  The problem with the implementation in
stdlib.scm is that all the arguments are evaluated before control
enters the function.  Besides being inefficient by doing unnecessary work,
if any of the arguments have side-effects you can make use of short-circuiting
by using &lt;code&gt;and&lt;/code&gt; to sequence actions, bailing out if any fail (by returning &lt;code&gt;nil&lt;/code&gt;),
and using &lt;code&gt;or&lt;/code&gt; to define a set of alternative actions which will bail out when the first in the list succeeds (by returning anything but &lt;code&gt;nil&lt;/code&gt;).  Had we macros then we could implement them as
macros.  We don’t, so we’ll write them as special forms in Haskell.&lt;/p&gt;


	&lt;p&gt;Unlike the special forms defined in the tutorial I’m going to
implement these as separate functions for clarity, rather than lump
them all in &lt;code&gt;eval&lt;/code&gt;.  However, they will be invoked directly from
&lt;code&gt;eval&lt;/code&gt; so their type is easy; it’s the same as &lt;code&gt;eval&lt;/code&gt;’s.&lt;/p&gt;


	&lt;p&gt;Code first, ask questions later.  Haskell is a pretty clear and
concise language.  My explanations may be redundant because of this.&lt;/p&gt;


	&lt;h3&gt;lispAnd&lt;/h3&gt;


&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;lispAnd :: Env -&amp;gt; [LispVal] -&amp;gt; IOThrowsError LispVal&lt;tt&gt;
&lt;/tt&gt;lispAnd env [] = return $ Bool True&lt;tt&gt;
&lt;/tt&gt;lispAnd env [pred] = eval env pred&lt;tt&gt;
&lt;/tt&gt;lispAnd env (pred:rest) = do&lt;tt&gt;
&lt;/tt&gt;    result &amp;lt;- eval env pred&lt;tt&gt;
&lt;/tt&gt;    case result of&lt;tt&gt;
&lt;/tt&gt;      Bool False -&amp;gt; return result&lt;tt&gt;
&lt;/tt&gt;      _ -&amp;gt; lispAnd env rest&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;Starting with the trivial case, &lt;code&gt;and&lt;/code&gt; returns &lt;code&gt;#t&lt;/code&gt; with zero
arguments.&lt;/p&gt;


	&lt;p&gt;With one argument, a single predicate, simply evaluate and
return that argument.&lt;/p&gt;


	&lt;p&gt;Given a list of predicates, evaluate the first and inspect its value.
If the argument evaluated to &lt;code&gt;#f&lt;/code&gt; then our work is done and we return
&lt;code&gt;#f&lt;/code&gt;, otherwise we keep plugging along by making a recursive call with
the first argument stripped off.  Eventually we will reach our base
case with only one predicate.&lt;/p&gt;


	&lt;p&gt;It’s possible to eliminate the case of one predicate.  I think that
just complicates things but it’s a viable solution.&lt;/p&gt;


	&lt;h3&gt;lispOr&lt;/h3&gt;


	&lt;p&gt;Predictably this is quite similar to &lt;code&gt;lispAnd&lt;/code&gt;.&lt;/p&gt;


&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;lispOr :: Env -&amp;gt; [LispVal] -&amp;gt; IOThrowsError LispVal&lt;tt&gt;
&lt;/tt&gt;lispOr env [] = return $ Bool False&lt;tt&gt;
&lt;/tt&gt;lispOr env [pred] = eval env pred&lt;tt&gt;
&lt;/tt&gt;lispOr env (pred:rest) = do&lt;tt&gt;
&lt;/tt&gt;    result &amp;lt;- eval env pred&lt;tt&gt;
&lt;/tt&gt;    case result of&lt;tt&gt;
&lt;/tt&gt;        Bool False -&amp;gt; lispOr env rest&lt;tt&gt;
&lt;/tt&gt;        _ -&amp;gt; return result&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;With no arguments &lt;code&gt;lispOr&lt;/code&gt; returns &lt;code&gt;#f&lt;/code&gt;, and with one argument it
evaluates and returns the result.&lt;/p&gt;


	&lt;p&gt;With 2 or more arguments the first is evaluated, but this time if the
result is &lt;code&gt;#f&lt;/code&gt; then we continue looking for a truthy value.  If the
result is anything else at all then it’s returned and we are done.&lt;/p&gt;


	&lt;h2&gt;A new branching construct&lt;/h2&gt;


	&lt;p&gt;First let me define a convenience function that I have added to
ElSchemo.  It maps a list of expressions to their values by evaluating
each one in the given environment.&lt;/p&gt;


&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;evalExprs :: Env -&amp;gt; [LispVal] -&amp;gt; IOThrowsError [LispVal]&lt;tt&gt;
&lt;/tt&gt;evalExprs env exprs = mapM (eval env) exprs&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;h3&gt;lispCond&lt;/h3&gt;


	&lt;p&gt;Again, &lt;code&gt;lispCond&lt;/code&gt; has the same type as &lt;code&gt;eval&lt;/code&gt;.&lt;/p&gt;


&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;lispCond :: Env -&amp;gt; [LispVal] -&amp;gt; IOThrowsError LispVal&lt;tt&gt;
&lt;/tt&gt;lispCond env (List (pred:conseq) : rest) = do&lt;tt&gt;
&lt;/tt&gt;    result &amp;lt;- eval env pred&lt;tt&gt;
&lt;/tt&gt;    case result of&lt;tt&gt;
&lt;/tt&gt;        Bool False -&amp;gt; if null rest then return result else lispCond env rest&lt;tt&gt;
&lt;/tt&gt;        _ -&amp;gt; liftM last $ evalExprs env conseq&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;Unlike Lisp – which uses a predicate of &lt;code&gt;T&lt;/code&gt; (true) – Scheme uses a
predicate of &lt;code&gt;else&lt;/code&gt; to trigger the default branch.  When the pattern
matching on &lt;code&gt;Atom "else"&lt;/code&gt; succeeds, we evaluate the default
expressions and return the value of the last one.  This is one
possible base case.  &lt;code&gt;Atom "else"&lt;/code&gt; could be defined to evaluate to
&lt;code&gt;#t&lt;/code&gt;, but we don’t want &lt;code&gt;else&lt;/code&gt; to be evaluated as &lt;code&gt;#t&lt;/code&gt; anywhere except
in a &lt;code&gt;cond&lt;/code&gt; so I have chosen this solution.&lt;/p&gt;


	&lt;p&gt;If the first predicate is not &lt;code&gt;else&lt;/code&gt; then we evaluate it and check the
resulting value.  If we get &lt;code&gt;#f&lt;/code&gt; then we look at the rest of the
statement, if it’s empty then we return &lt;code&gt;#f&lt;/code&gt;, otherwise we recurse on
the rest of the parameters.  If the predicate evaluates to a truthy
value – that is, anything but &lt;code&gt;#f&lt;/code&gt; – then we evaluate the consequent
expressions and return the value of the last one.&lt;/p&gt;


	&lt;h2&gt;Plumbing&lt;/h2&gt;


	&lt;p&gt;Now all that’s left is to hook up the new functions in &lt;code&gt;eval&lt;/code&gt;.&lt;/p&gt;


&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;eval env (List (Atom &amp;quot;and&amp;quot; : params)) = lispAnd env params&lt;tt&gt;
&lt;/tt&gt;eval env (List (Atom &amp;quot;or&amp;quot; : params)) = lispOr env params&lt;tt&gt;
&lt;/tt&gt;eval env (List (Atom &amp;quot;cond&amp;quot; : params)) = lispCond env params&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;You could, of course, throw the entire definitions in &lt;code&gt;eval&lt;/code&gt; itself but &lt;code&gt;eval&lt;/code&gt; is big
enough for me as it is.  &lt;span class="caps"&gt;YMMV&lt;/span&gt;.&lt;/p&gt;


	&lt;h2&gt;Done!&lt;/h2&gt;


	&lt;p&gt;So, that’s a wrap.  It only took 20 lines of code for the 3 new
special forms, and it could easily be done with less code.  Next time
I will show you how to implement the various &lt;code&gt;let&lt;/code&gt; functions.  Really!&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;Do you like me describing ElSchemo piece by piece as I have been?  I
plan on posting the Haskell code and my stdlib.scm in their entirety
sometime, and I could do that before or after I finish writing about
the features I’ve developed beyond the tutorial.  Just let me know in
the comments.&lt;/em&gt;&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/PhpQUlcZyYM" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/8/2/elschemo-boolean-logic-and-branching</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-07-12:157</id>
    <published>2007-07-12T19:28:00Z</published>
    <updated>2007-07-12T20:10:24Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/6rxLWkbE_0M/poeple" rel="alternate" type="text/html" />
    <title>people</title>
<content type="html">
            &lt;p&gt;Sometimes this is difficult to remember for someone who (likes to think that he) thinks somewhat logically.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;When dealing with people, let us remember that we are not dealing with creatures of logic.  We are dealing with creatures of emotion, creatures bristling with prejudices and motivated by pride and vanity.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;—&lt;a href="http://en.wikipedia.org/wiki/Dale_Carnegie"&gt;Dale Carnegie&lt;/a&gt;, &lt;em&gt;&lt;a href="http://en.wikipedia.org/wiki/How_to_Win_Friends_and_Influence_People"&gt;How to Win Friends and Influence People&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/6rxLWkbE_0M" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/7/12/poeple</feedburner:origLink></entry>
  <entry xml:base="http://sami.samhuri.net/">
    <author>
      <name>sjs</name>
    </author>
    <id>tag:sami.samhuri.net,2007-07-06:133</id>
    <published>2007-07-06T23:45:00Z</published>
    <updated>2007-07-06T23:46:29Z</updated>
    <link href="http://feedproxy.google.com/~r/sjs/~3/20Ch7PgXtLo/see-your-regular-expressions-in-emacs" rel="alternate" type="text/html" />
    <title>See your regular expressions in Emacs</title>
<content type="html">
            &lt;p&gt;First, if you are an Emacs newbie then be sure to read (at least) the introduction of &lt;a href="http://stuff.mit.edu/iap/emacs"&gt;Being Productive with Emacs&lt;/a&gt;. For some reason the &lt;span class="caps"&gt;PDF&lt;/span&gt; and &lt;span class="caps"&gt;HTML&lt;/span&gt; versions are slightly similar.&lt;/p&gt;


	&lt;p&gt;Anyway, it mentions &lt;code&gt;re-builder&lt;/code&gt; which is an awesome little gem if you use regular expressions at all&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;. What this baby does is open a small window at the bottom of your screen in which you can type a regex.  It is parsed as you type it and matches are highlighted in the other window. Genius.&lt;/p&gt;


	&lt;p&gt;[1] If you don’t use them I encourage you to “learn them”http://regex.info/. Don’t pay any attention to &lt;a href="http://regex.info/blog/2006-09-15/247"&gt;Jamie Zawinsky&lt;/a&gt; and his lack of appreciation for a fantastic tool.&lt;/p&gt;
          &lt;img src="http://feeds.feedburner.com/~r/sjs/~4/20Ch7PgXtLo" height="1" width="1"/&gt;</content>  <feedburner:origLink>http://sami.samhuri.net/2007/7/6/see-your-regular-expressions-in-emacs</feedburner:origLink></entry>
</feed>
