<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "/static/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>null program   </title>
    <link>http://nullprogram.com/blog</link>
    <description>Hobby Computing</description>
    <language>en</language>

  <item>
    <title>A Fractran Short Story</title>
    <link>http://nullprogram.com/blog/2010/03/09</link>
    <description>&lt;!-- 9 March 2010 --&gt;
&lt;p&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Fractran&quot;&gt;Fractran&lt;/a&gt; is a
Turing-complete esoteric programming language. A Fractran program is
just an ordered list of positive, irreducible fractions. The program's
output for an input &lt;i&gt;n&lt;/i&gt; is the output of the program run
on &lt;i&gt;n&lt;/i&gt; multiplied by the first fraction in the list that results
in an integer. If no such multiplication results in an integer, the
output is the input &lt;i&gt;n&lt;/i&gt;. Variables are encoded in the exponents
of the prime factorization of the input and output.
&lt;/p&gt;
&lt;p&gt;
Some time ago I thought up an idea for a short story involving
Fractran. A mathematician accidentally creates a Fractran program that
can trivially factor large composites. Think something like
O(log &lt;i&gt;n&lt;/i&gt;). It's just the right magical string of, say, 31
fractions.
&lt;/p&gt;
&lt;p&gt;
The story would be a first-person narrative of the mathematician's
thoughts during a short time after the discovery, considering many of
the consequences of the program. For example, it would render much of
cryptography, which plays an essential role in the modern world,
useless. He would also wonder if mankind should deserve such a
discovery, considering how accidental it was.
&lt;/p&gt;
&lt;p&gt;
This whole idea vanished once I realized that this Fractran program is
actually completely trivial. It even runs in O(1) time. It's so
trivial as to be worthless. Remember that Fractran stores its data in
the number's prime factorization? The Fractran program that can factor
any number in constant time is the identity function. To decode the
output, which matches the input, all you need to do is factor it!
&lt;/p&gt;
&lt;p&gt;
Interestingly, it doesn't seem to actually be possible to implement
the identity function in Fractran (&lt;i&gt;But somehow it's
Turing-complete? Hmmm... more investigation needed.&lt;/i&gt;), unless you
can define your program in terms of its input. For example, the
program &lt;code&gt;1/(n+1)&lt;/code&gt; is the identity function for
input &lt;i&gt;n&lt;/i&gt;.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Function Pointers are Special</title>
    <link>http://nullprogram.com/blog/2010/02/18</link>
    <description>&lt;!-- 18 February 2010 --&gt;
&lt;p&gt;
Here's something I only learned recently, since it came up when
working on &lt;a href=&quot;/blog/2010/01/24/&quot;&gt; Wisp&lt;/a&gt;. In C function
pointers are incompatible with normal pointers. For example, this is
unportable C,
&lt;/p&gt;
&lt;pre&gt;
int func (int x);

int main ()
{
  void *p = (void *) &amp;amp;func;
}
&lt;/pre&gt;
&lt;p&gt;
This is because function pointers are larger than other pointers on
some architectures. If the compiler in such a scenario allowed this
perhaps it would overflow the pointer and corrupt some other data,
like the stack, or, more likely, only part of the pointer would be
copied. It wasn't until I added the &lt;code&gt;-pedantic&lt;/code&gt; flag to gcc
that it started warning me about situations like the
above. The &lt;code&gt;-W -Wall&lt;/code&gt; flags are silent here.
&lt;/p&gt;
&lt;p&gt;
I bet this issue only comes up very rarely. How often do you have to
store a function pointer in a void pointer? It subverts the type
system and is generally a bad idea. I had to do it in Wisp as part of
its value polymorphism, which is why it bit me. This is probably why
gcc doesn't get very picky over it.
&lt;/p&gt;
&lt;p&gt;
This also means function pointers have less support than normal
pointers. For example, printing pointers
with &lt;code&gt;printf()&lt;/code&gt;'s &lt;code&gt;%p&lt;/code&gt; won't work, since it
expects a &lt;code&gt;void&lt;/code&gt; pointer, so there's no printing them. You
can't sort them with &lt;code&gt;qsort()&lt;/code&gt;. You can even treat the
function pointer as a blob of data to manipulate manually since
there's no safe way to make a regular pointer to it. Really, almost
any C library function that accepts pointers won't work with function
pointers.
&lt;/p&gt;
&lt;p&gt;
So if you want a tricky, unfair, interview question this could be
one!
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Common Lisp Quick Reference</title>
    <link>http://nullprogram.com/blog/2010/02/06</link>
    <description>&lt;!-- 6 February 2010 --&gt;
&lt;p&gt;
I found this &lt;a href=&quot;http://clqr.berlios.de/&quot;&gt; Common Lisp Quick
Reference&lt;/a&gt; the other day
from &lt;a href=&quot;http://www.reddit.com/r/lisp/&quot;&gt; r/lisp&lt;/a&gt;, and I think
it's &lt;i&gt;fantastic&lt;/i&gt;. It's a comprehensive, libre booklet of the
symbols defined by the Common Lisp ANSI standard. Very slick!
&lt;/p&gt;
&lt;p&gt;
The main version is meant to be printed out and nested with a vertical
fold, and it works quite well. If I ever get a chance to use Common
Lisp at work (a man can dream), probably at a location without
Internet access, this could come in handy. So I printed out one for
myself,
&lt;/p&gt;
&lt;p class=&quot;center&quot;&gt;
&lt;a href=&quot;/img/clqr/front.jpg&quot;&gt;&lt;img src=&quot;/img/clqr/front-thumb.jpg&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;
&lt;a href=&quot;/img/clqr/open.jpg&quot;&gt;&lt;img src=&quot;/img/clqr/open-thumb.jpg&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In case the website ever disappears in the future, here's all the PDFs
and LaTeX source for it. These could be out of date, so you should
check the main website first.
&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;/download/clqr/clqr-a4-booklet-all.pdf&quot;&gt;
clqr-a4-booklet-all.pdf&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;/download/clqr/clqr-a4-booklet-four.pdf&quot;&gt;
clqr-a4-booklet-four.pdf&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;/download/clqr/clqr-a4-consec.pdf&quot;&gt;
clqr-a4-consec.pdf&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;/download/clqr/clqr-letter-booklet-all.pdf&quot;&gt;
clqr-letter-booklet-all.pdf&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;/download/clqr/clqr-letter-booklet-four.pdf&quot;&gt;
clqr-letter-booklet-four.pdf&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;/download/clqr/clqr-letter-consec.pdf&quot;&gt;
clqr-letter-consec.pdf&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;/download/clqr/clqr.tar.gz&quot;&gt;
clqr.tar.gz&lt;/a&gt; (LaTeX source)
&lt;/p&gt;
&lt;p&gt;
And a local clone,
&lt;/p&gt;
&lt;pre&gt;
git clone &lt;a href=&quot;http://git.nullprogram.com/?p=clqr.git;a=summary&quot;&gt;http://git.nullprogram.com/clqr.git&lt;/a&gt;
&lt;/pre&gt;</description>
  </item>
  <item>
    <title>Wisp Screencasts</title>
    <link>http://nullprogram.com/blog/2010/02/04</link>
    <description>&lt;!-- 4 February 2010 --&gt;
&lt;p&gt;
I've been chugging away on &lt;a href=&quot;http://wisp.nullprogram.com/&quot;&gt;
Wisp&lt;/a&gt;, &lt;a href=&quot;/blog/2010/01/24/&quot;&gt;announced in my last post&lt;/a&gt;,
every day since I started it a few weeks ago, and it's becoming a
pretty solid system. There's now an exception system, reference
counting for dealing with garbage, and a reentrant parser. It's no
replacement for any other lisps, but I've found it to be very fun to
work on. I've put what exists so far of
the &lt;a href=&quot;http://wisp.nullprogram.com/wisp-guide.html&quot;&gt; Wisp User
Guide&lt;/a&gt; up for viewing. The AsciiDoc source is in the Git
repository, which is here,
&lt;/p&gt;
&lt;pre&gt;
git clone &lt;a href=&quot;http://git.nullprogram.com/?p=wisp.git;a=summary&quot;&gt;http://git.nullprogram.com/wisp.git&lt;/a&gt;
&lt;/pre&gt;
&lt;p&gt;
I wanted to show off some of the new features of Wisp, and since I was
inspired by &lt;a href=&quot;http://vimeo.com/channels/fulldisclojure&quot;&gt; Full
Disclojure&lt;/a&gt;, since it's so damn slick, I decided to make some
screencasts of Wisp in action. All of the screencast software for
GNU/Linux is pretty poor, but after a few hours of head-banging I
managed to hobble something together for you. Enjoy!
&lt;/p&gt;
&lt;p&gt;
  &lt;video src=&quot;/video/wisp/wisp-memoize.ogv&quot; controls&gt;
    Since your browser doesn't seem to support the video tag, here's a
    link to the video: &lt;a href=&quot;/video/wisp/wisp-memoize.ogv&quot;&gt;
    wisp-memoize.ogv&lt;/a&gt;.
  &lt;/video&gt;
&lt;/p&gt;
&lt;p&gt;
That video demonstrated the memoization function. It can be pulled in
from the &lt;code&gt;memoize&lt;/code&gt; library. You give it a symbol, which
should have a function definition stored in it, and it will installed a
wrapper around it. In the video I used the Fibonacci function from
the &lt;code&gt;examples&lt;/code&gt; library.
&lt;/p&gt;
&lt;pre&gt;
(require 'examples)
(fib 30) ; Slooooow ...
(memoize 'fib)
(fib 100) ; Fast!
&lt;/pre&gt;
&lt;p&gt;
  &lt;video src=&quot;/video/wisp/wisp-detach.ogv&quot; controls&gt;
    Since your browser doesn't seem to support the video tag, here's a
    link to the video: &lt;a href=&quot;/video/wisp/wisp-detach.ogv&quot;&gt;
    wisp-detach.ogv&lt;/a&gt;.
  &lt;/video&gt;
&lt;/p&gt;
&lt;p&gt;
This demonstrated the &quot;detachment&quot; feature of Wisp, which is similar
to &quot;futures&quot; in Clojure. It forks off a new process, which executes
the given function. The &lt;code&gt;send&lt;/code&gt; function can be used in the
detached process to send any lisp objects back to the parents, which
can receive them with the &lt;code&gt;receive&lt;/code&gt;
function. The &lt;code&gt;send&lt;/code&gt; function can be called any number of
times to continually send data back. The &lt;code&gt;receive&lt;/code&gt; function
will block if there is no lisp object to receive yet.
&lt;/p&gt;
&lt;pre&gt;
(require 'examples)
(setq d (detach (lambda () (send (fib)))))
(receive d) ; Gets value from child process
&lt;/pre&gt;
&lt;p&gt;
  &lt;video src=&quot;/video/wisp/wisp-point-free.ogv&quot; controls&gt;
    Since your browser doesn't seem to support the video tag, here's a
    link to the video: &lt;a href=&quot;/video/wisp/wisp-point-free.ogv&quot;&gt;
    wisp-point-free.ogv&lt;/a&gt;.
  &lt;/video&gt;
&lt;/p&gt;
&lt;p&gt;
This video shows off the point-free functions that have been defined:
function composition and partial application (I accidentally say
&quot;partial evaluation&quot; in the video). These are actually just simple
macros that any lisp could do.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Wisp Lisp</title>
    <link>http://nullprogram.com/blog/2010/01/24</link>
    <description>&lt;!-- 24 January 2010 --&gt;
&lt;p class=&quot;abstract&quot;&gt;
Update 2010-2-04: A lot of the information below is out of date. There
is an update here: &lt;a href=&quot;/blog/2010/02/04/&quot;&gt;Wisp Screencasts&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;/img/wisp.png&quot; alt=&quot;&quot; title=&quot;A wisp of a lisp&quot; class=&quot;right&quot;/&gt;

This is a project I've been wanting to do for some time, and I finally
got around to doing it. I spent the last few days implementing my own
lisp interpreter in C. Today, after sinking in about 48 hours of work,
I believe I completed enough of it to consider it in a working state,
with a code base stable enough that other interested people could
contribute. It was &lt;i&gt;really&lt;/i&gt; exciting to see everything come together
today.
&lt;/p&gt;
&lt;p&gt;
You can make a clone of the Wisp repository with Git. Go ahead; don't
be shy,
&lt;/p&gt;
&lt;pre&gt;
git clone &lt;a href=&quot;http://git.nullprogram.com/?p=wisp.git;a=summary&quot;&gt;http://git.nullprogram.com/wisp.git&lt;/a&gt;
&lt;/pre&gt;
&lt;p&gt;
To build it, all you need is a C99 compiler, make, yacc
(i.e. &lt;a href=&quot;http://www.gnu.org/software/bison/&quot;&gt; Bison&lt;/a&gt;), and
lex (i.e. &lt;a href=&quot;http://flex.sourceforge.net/&quot;&gt; Flex&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
It doesn't use the readline library or one of it's clones to make a
nice interaction command line, so it's a good idea to run it
with &lt;a href=&quot;http://utopia.knoware.nl/~hlub/uck/rlwrap/&quot;&gt;rlwrap&lt;/a&gt;. That's
what I've been doing. If you plan on writing Wisp code in Emacs,
putting this in your &lt;code&gt;.emacs&lt;/code&gt; will give you all the syntax
niceties,
&lt;/p&gt;
&lt;pre&gt;
(add-to-list 'auto-mode-alist '(&lt;span class=&quot;string&quot;&gt;&quot;.wisp\\'&quot;&lt;/span&gt; . lisp-mode))
&lt;/pre&gt;
&lt;p&gt;
You should also be able to run it as an inferior lisp and send code to
it like a normal lisp. I haven't done this yet myself.
&lt;/p&gt;
&lt;p&gt;
I think the name is apt, because it really is a wisp of a lisp. As of
this writing, it weighs in at 1500 lines of code and is still very
feature-light. I haven't actually read any material about writing lisp
interpreters, so I've been winging it based on my experience with
it. It's already taught me a lot of subtle things about lisp that I
hadn't been aware of before.
&lt;/p&gt;
&lt;p&gt;
Right know it's very simple. It doesn't yet support any syntax beyond
parenthesis (no &lt;code&gt;'&lt;/code&gt; quoting). No closures. No garbage
collection, as I'm still working out how I'm going to do
that. Dynamically scoped, since that's a lot easier to do. And, like
Scheme, it's a lisp-1, meaning functions and variables share a common
namespace. I hope to expand it to include some features from other
lisps like Arc (particularly the anonymous function syntactical
sugar), Common Lisp, and Scheme.
&lt;/p&gt;
&lt;p&gt;
However, it &lt;i&gt;does&lt;/i&gt; have already anonymous functions, which many
popular languages &lt;i&gt;still&lt;/i&gt; don't have. :-) It's far enough along
to let you define crazy stuff like this,
&lt;/p&gt;
&lt;pre&gt;
(&lt;span class=&quot;keyword&quot;&gt;defun&lt;/span&gt; &lt;span class=&quot;function-name&quot;&gt;example&lt;/span&gt; (n)
  (&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&amp;lt;= n 0)
      (&lt;span class=&quot;keyword&quot;&gt;lambda&lt;/span&gt; (x) (* x 10))
    (&lt;span class=&quot;keyword&quot;&gt;lambda&lt;/span&gt; (x) (* x 2.0))))
&lt;/pre&gt;
&lt;p&gt;
Which you can call, interactively in this case, like so,
&lt;/p&gt;
&lt;pre&gt;
wisp&gt; ((example  1) 20)
40.000000
wisp&gt; ((example -1) 20)
200
&lt;/pre&gt;
&lt;p&gt;
Because there's no garbage collection yet, it leaks memory like a
sieve. For garbage collection, I think I'll do a mark-and-sweep,
marking objects based on their reachability from the symbol
table. That still leaves some corner cases -- such as worrying about
objects in limbo in the evaluator -- that I'm not sure about. I need
to be careful not to free objects still in use. Still working that one
out.
&lt;/p&gt;
&lt;p&gt;
It has the multiplication, addition, subtraction, and division
implemented, as well as the greater-than and less-than operators. Lisp
macros are implemented. A number of special forms are defined, like
let, if, set, defun, defmacro, car, cdr, not, progn, lambda, and
while. All of the predicates are implemented. It has a C interface,
which is how all the above got defined. I already have some functions
and macros defined in terms of Wisp code, too. Most of the needed
functions at this point are trivial to add, though a bit tedious, so
I'm mostly trying to focus on the core parts of the interpreter right
now.
&lt;/p&gt;
&lt;p&gt;
It's amazing how much the internal code looks like lisp written in a C
dialect. I have CAR and CDR macros defined, which get used all over
the place, and code frequently uses them to walk lists like lisp code
would.
&lt;/p&gt;
&lt;p&gt;
The core struct that everything works with the the object struct. It's
defined as such,
&lt;/p&gt;
&lt;pre&gt;
&lt;span class=&quot;keyword&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;object&lt;/span&gt;
{
  &lt;span class=&quot;type&quot;&gt;type_t&lt;/span&gt; &lt;span class=&quot;variable-name&quot;&gt;type&lt;/span&gt;;
  &lt;span class=&quot;type&quot;&gt;void&lt;/span&gt; *&lt;span class=&quot;variable-name&quot;&gt;val&lt;/span&gt;;
} &lt;span class=&quot;variable-name&quot;&gt;object_t&lt;/span&gt;;
&lt;/pre&gt;
&lt;p&gt;
The &lt;code&gt;type_t&lt;/code&gt; field comes from this enumeration,
&lt;/p&gt;
&lt;pre&gt;
&lt;span class=&quot;keyword&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;types&lt;/span&gt;
  { INT, FLOAT, STRING, SYMBOL, CONS, CFUNC, SPECIAL } &lt;span class=&quot;variable-name&quot;&gt;type_t&lt;/span&gt;;
&lt;/pre&gt;
&lt;p&gt;
The type indicates what type of data the void pointer points to,
making it sort-of polymorphic. Note the CONS type, the cons cell, used
to create lists,
&lt;/p&gt;
&lt;pre&gt;
&lt;span class=&quot;keyword&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;type&quot;&gt;cons&lt;/span&gt;
{
  &lt;span class=&quot;type&quot;&gt;object_t&lt;/span&gt; *&lt;span class=&quot;variable-name&quot;&gt;car&lt;/span&gt;;
  &lt;span class=&quot;type&quot;&gt;object_t&lt;/span&gt; *&lt;span class=&quot;variable-name&quot;&gt;cdr&lt;/span&gt;;
} &lt;span class=&quot;variable-name&quot;&gt;cons_t&lt;/span&gt;;
&lt;/pre&gt;
&lt;p&gt;
There's the familiar car and cdr pointers. There are a bunch of helper
functions to manipulate and build these. For
example, &lt;code&gt;c_cons()&lt;/code&gt; creates a cons cell,
&lt;/p&gt;
&lt;pre&gt;
&lt;span class=&quot;type&quot;&gt;object_t&lt;/span&gt; *&lt;span class=&quot;function-name&quot;&gt;c_cons&lt;/span&gt; (&lt;span class=&quot;type&quot;&gt;object_t&lt;/span&gt; * &lt;span class=&quot;variable-name&quot;&gt;car&lt;/span&gt;, &lt;span class=&quot;type&quot;&gt;object_t&lt;/span&gt; * &lt;span class=&quot;variable-name&quot;&gt;cdr&lt;/span&gt;);
&lt;/pre&gt;
&lt;p&gt;
Look familiar? Yup, that's the lisp &lt;code&gt;cons&lt;/code&gt; function. Since
the &lt;code&gt;nil&lt;/code&gt; symbol is available in C code as &lt;code&gt;NIL&lt;/code&gt;
you can chain these together in C to make a list,
&lt;/p&gt;
&lt;pre&gt;
object_t *lst = c_cons (c_int(10), c_cons (c_str (&quot;hello&quot;), NIL));
&lt;/pre&gt;
&lt;p&gt;
Which puts together the simple list,
&lt;/p&gt;
&lt;pre&gt;
(10 &quot;hello&quot;)
&lt;/pre&gt;
&lt;p&gt;
Since that's so cumbersome to write out, there's a parser that can
read nice lisp code and use all those same functions to make the
lists. Hence, the lisp reader.
&lt;/p&gt;
&lt;p&gt;
If you want to help, it's pretty easy to add more CFUNCs, C functions
that are exposed to Wisp lisp code. Right now, I'd like to expose the
whole C math.h library, provide a nice I/O interface, and expose a
bunch of string functions. The &lt;code&gt;TODO&lt;/code&gt; file in the
repository contains more things to be done.
&lt;/p&gt;
&lt;p&gt;
Wisp will probably be getting it's own &quot;project page&quot; here at some
point in the future. When it does, I'll update this post to point to
it.
&lt;/p&gt;
&lt;p&gt;
Oh, and I decided to make this available under a 2-clause BSD license,
so someone could easily plug it into another program as an extension
language (once Wisp has matured first, of course). That would be
cool.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Setting up a Common Lisp Environment</title>
    <link>http://nullprogram.com/blog/2010/01/15</link>
    <description>&lt;!-- 15 January 2010 --&gt;
&lt;p&gt;
Common Lisp is possibly the most advanced programming language. Think
of pretty much any programming language feature and Common Lisp
probably has it. Since lisp is the programmable programming language,
when someone invents a new language feature it can probably be added
to Common Lisp without even touching the language core.
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;/img/emacs-slime.png&quot; alt=&quot;&quot; title=&quot;SBCL SLIME REPL&quot;
     class=&quot;right&quot;/&gt;

However, if you're interested in digging into Common Lisp to try it
out, you may find yourself quickly running into walls just getting
started. It's a lot different than other programming environments you
may be used to. The Common Lisp tutorials generally skip this step,
assuming the user has an environment, or leaving that setup for the
&quot;vendor&quot; to handle. So, here's a guide to setting up a great Common
Lisp environment with &lt;a href=&quot;http://www.gnu.org/software/emacs/&quot;&gt;
Emacs&lt;/a&gt; and &lt;a href=&quot;http://common-lisp.net/project/slime/&quot;&gt;
SLIME&lt;/a&gt;. It should work with any Common Lisp implementation and any
operating system that can run Emacs (i.e. most of them). Even a much
less capable one like Windows.
&lt;/p&gt;
&lt;p&gt;
First, you need to pick a Common Lisp implementation and install
it. Ideally, it should end up in your PATH. Like C, the language is
defined solely by its standardized specification, rather than some
canonical implementation. &lt;a href=&quot;http://www.sbcl.org/&quot;&gt; Steel Bank
Common Lisp&lt;/a&gt; (SBCL) is currently
the &lt;a href=&quot;http://www.cliki.net/Benchmarks&quot;&gt;
highest&lt;/a&gt; &lt;a href=&quot;http://john.freml.in/sbcl-optimise&quot;&gt;
performing&lt;/a&gt; implementation, it's Free Software, and it runs on a
wide variety of platforms, so take a look at that one if you're not
sure.
&lt;/p&gt;
&lt;p&gt;
Next, install Emacs. We're using Emacs not just because it's the best
text editor ever created. &lt;code&gt;:-D&lt;/code&gt; It's because that's what
SLIME is written for, and Emacs is a lisp-aware editor. Really, Emacs
is a lisp interpreter that &lt;i&gt;happens&lt;/i&gt; to be geared towards
text-editing. It's accused of breaking the rules of unix by being a
single, monolithic program, but it's really a whole bunch of small
lisp programs. You can even have a lisp REPL in Emacs
(&lt;code&gt;ielm&lt;/code&gt;), similar to what we will have once we're done
here. It's plays very well with Common Lisp.
&lt;/p&gt;
&lt;p&gt;
If you're unfamiliar with Emacs, you should stop here and familiarize
yourself with it a bit. Really, you could spend a decade learning
Emacs and still have more to learn. The tutorial should be good enough
for now. Fire up Emacs and run the tutorial by pressing
&lt;code&gt;control+h&lt;/code&gt; then &lt;code&gt;t&lt;/code&gt;. In Emacs notation,
that's &lt;code&gt;C-h t&lt;/code&gt;. &lt;code&gt;C-h&lt;/code&gt; is the help/documentation
prefix, which can be used to look up variables/symbols
(&lt;code&gt;v&lt;/code&gt;), functions (&lt;code&gt;f&lt;/code&gt;), key bindings
(&lt;code&gt;k&lt;/code&gt;), info manuals (&lt;code&gt;i&lt;/code&gt;), the current mode
(&lt;code&gt;m&lt;/code&gt;), and apropos (searching) (&lt;code&gt;a&lt;/code&gt;). In the
info manuals, you should be able to find the full Emacs manual, Elisp
reference, and Elisp tutorial, since they are generally installed
alongside Emacs these days. Nearly anything you might need to know can
be found inside the included documentation.
&lt;/p&gt;
&lt;p&gt;
Next, install SLIME. I'll be a bit more specific for this one. Make
a &lt;code&gt;.emacs.d&lt;/code&gt; directory in your home directory (whatever
your HOME environmental variable is set to). This is a common place to
put user-installed Emacs extensions. You will be putting
your &lt;code&gt;slime&lt;/code&gt; directory in here. There are two basic ways to
obtain SLIME, as indicated right on their main page. You can do a CVS
checkout of the SLIME repository, which allows you to follow it and
run the latest version. Or you can grab a snapshot of the repository,
which is provided, and dump it in there. Since I like you so much,
I'll give you a third option. Here's a Git repository, maintained by
someone very kind, that follows SLIME's CVS repository,
&lt;/p&gt;
&lt;pre&gt;
git clone git://git.boinkor.net/slime.git
&lt;/pre&gt;
&lt;p&gt;
Ultimately, you should have a directory &lt;code&gt;~/.emacs.d/slime/&lt;/code&gt;
that contains a bunch of SLIME source files directly inside.
&lt;/p&gt;
&lt;p&gt;
Now, we tell Emacs where SLIME is and how to use it. Make
a &lt;code&gt;.emacs&lt;/code&gt; file in your home directory, if you haven't
already, and put this in it,
&lt;/p&gt;
&lt;pre&gt;
(add-to-list 'load-path &lt;span class=&quot;string&quot;&gt;&quot;~/.emacs.d/slime/&quot;&lt;/span&gt;)
(&lt;span class=&quot;keyword&quot;&gt;require&lt;/span&gt; '&lt;span class=&quot;constant&quot;&gt;slime&lt;/span&gt;)
(slime-setup '(slime-repl))
&lt;/pre&gt;
&lt;p&gt;
Once it's saved, either restart Emacs, or simply evaluate those lines
by putting the cursor after each them in turn and typing &lt;code&gt;C-x
C-e&lt;/code&gt;. If you did everything right so far, you shouldn't have any
errors. (If you did, go back up and see what you did wrong.) If your
Common Lisp installation didn't end up in your PATH as
&quot;&lt;code&gt;lisp&lt;/code&gt;&quot; (not uncommon) for some reason, you may need to
tell Emacs where it is. For example, I can point directly to my SBCL
installation with this line,
&lt;/p&gt;
&lt;pre&gt;
(setq inferior-lisp-program &lt;span class=&quot;string&quot;&gt;&quot;/usr/bin/sbcl&quot;&lt;/span&gt;)
&lt;/pre&gt;
&lt;p&gt;
If everything is set up right, fire up SLIME with &quot;&lt;code&gt;M-x
slime&lt;/code&gt;&quot;. It should compile the back-end, called swank, and run a
Common Lisp REPL as an inferior process to Emacs. You should end up
with a nice prompt like this,
&lt;/p&gt;
&lt;pre&gt;
CL-USER&gt;
&lt;/pre&gt;
&lt;p&gt;
At this line, you can start evaluating lisp expressions as you
please. But this isn't where the true power of SLIME comes in
yet. I'll give you an example: make a new file with
a &lt;code&gt;.lisp&lt;/code&gt; extension and open it. Throw some lisp in there,
&lt;/p&gt;
&lt;pre&gt;
(&lt;span class=&quot;keyword&quot;&gt;defun&lt;/span&gt; &lt;span class=&quot;function-name&quot;&gt;adder&lt;/span&gt; (x)
  (&lt;span class=&quot;keyword&quot;&gt;lambda&lt;/span&gt; (y) (+ x y)))
&lt;/pre&gt;
&lt;p&gt;
Type &lt;code&gt;C-x C-k&lt;/code&gt; and it will send the current buffer over to
be compiled and loaded. This code here uses a closure, so you know you
aren't accidentally using Emacs lisp, as it doesn't have closures. At
the REPL you can call it,
&lt;/p&gt;
&lt;pre&gt;
CL-USER&gt; (funcall (adder 5) 6)
&lt;/pre&gt;
&lt;p&gt;
Which will print the return value, &lt;code&gt;11&lt;/code&gt;. That's all there
is to it. You write code in the buffer, then with a simple keystroke
send it to the Common Lisp system to be evaluated and loaded. Because
the SLIME key bindings eclipse the Emacs lisp key bindings, you can
type this same line in the lisp source buffer place the cursor at the
end, and type C-x C-e, which will send it out to Common Lisp to be
evaluated. Look at the mode help (&lt;code&gt;C-h m&lt;/code&gt;) to see all the
key bindings made available.
&lt;/p&gt;
&lt;p&gt;
This is a great programming environment that makes Common Lisp all the
more fun to use. You run a single, continuous instance if your program
growing it gradually. (This is exactly how I
built &lt;a href=&quot;/blog/2009/05/17/&quot;&gt;my Emacs web server&lt;/a&gt; with elisp.)
You can test your code as soon as soon as it's written.
&lt;/p&gt;
&lt;p&gt;
The setup can get even more advanced. The Common Lisp REPL need not be
running on the same computer. It can be running on another computer,
as long as SLIME is able to connect to it over the network. Several
developers could even share a single Common Lisp process running on a
common machine. Lots of possibilities.
&lt;/p&gt;
&lt;p&gt;
If you don't have a Common Lisp book yet,
there's &lt;a href=&quot;http://gigamonkeys.com/book/&quot;&gt;Practical Common
Lisp&lt;/a&gt;, which you can read at no cost online
or &lt;a href=&quot;http://www.computer-books.us/lisp_0004.php&quot;&gt;download&lt;/a&gt;
for reading offline. It's based on an Emacs and SLIME setup, so you'll
be right on track.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Magick Thumbnails</title>
    <link>http://nullprogram.com/blog/2009/12/21</link>
    <description>&lt;!-- 21 December 2009 --&gt;
&lt;p&gt;
&lt;img src=&quot;/img/literal-thumbnail.jpg&quot; alt=&quot;&quot; class=&quot;right&quot;
     title=&quot;No, not this.&quot;/&gt;

For a long time I couldn't figure out how to make decent thumbnails
with &lt;a href=&quot;http://www.imagemagick.org/script/index.php&quot;&gt;
ImageMagick&lt;/a&gt;. Specifically, I wanted to create uniform sized
thumbnails from arbitrary images. Over the weekend I came across the
&lt;a href=&quot;http://www.imagemagick.org/Usage/thumbnails/#cut&quot;&gt;
ImageMagick Examples page&lt;/a&gt;, which shows exactly how to do
this. Here's the command for a 150x150 thumbnail,
&lt;/p&gt;
&lt;pre&gt;
convert orig.jpg -thumbnail 150x150^ -gravity center \
        -extent 150x150 thumb.jpg
&lt;/pre&gt;
&lt;p&gt;
It cuts out the largest square possible from the center of the image
and resizes that to 150x150. This capability has actually only been
available for 2 years now! It wasn't there last time I needed it.
&lt;/p&gt;
&lt;p&gt;
I can think of one way to improve it: instead of selecting the center,
it selects the area with the highest information density. This could
be measured by edge detection, corner detection, or some other
statistical method. It would be selected by changing the gravity
option to, say, &quot;entropy&quot;.
&lt;/p&gt;
&lt;p&gt;
I'm listing this here mostly for my own future reference. :-)
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Game of Life in Java</title>
    <link>http://nullprogram.com/blog/2009/12/13</link>
    <description>&lt;!-- 13 December 2009 --&gt;
&lt;p&gt;
Sources:
&lt;/p&gt;
&lt;pre&gt;
git clone &lt;a href=&quot;http://git.nullprogram.com/?p=GameOfLife.git;a=summary&quot;&gt;http://git.nullprogram.com/GameOfLife.git&lt;/a&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;img src=&quot;/img/game-of-life.png&quot; width=&quot;250&quot;
     alt=&quot;&quot; title=&quot;Screenshot of this thing&quot; class=&quot;right&quot;/&gt;

Compiled (2009-12-13): &lt;a href=&quot;/download/GoL.jar&quot;&gt;GoL.jar&lt;/a&gt; (6.7kb)
&lt;/p&gt;
&lt;p&gt;
Since I recently got back into Java recently, I threw together this
little Game of Life implementation in Java. It looks a lot like my &lt;a
href=&quot;/blog/2007/10/08/&quot;&gt;maze generator/solver&lt;/a&gt; on the inside,
reflecting the way I think about these things. Gavin wrote a &lt;a
href=&quot;http://devrand.org/show_item.html?item=98&amp;amp;page=Project&quot;&gt;
competing version of the game&lt;/a&gt; in &lt;a
href=&quot;http://processing.org/&quot;&gt;Processing&lt;/a&gt; which we were partially
discussing the other night, so I made my own.
&lt;/p&gt;
&lt;p&gt;
The individual cells are actually objects themselves, so you could
inherit the abstract Cell class and drop in your own rules. I bet you
could even write a Cell that does the &lt;a href=&quot;/blog/2007/11/06/&quot;&gt;
iterated prisoner's dilemma cellular automata&lt;/a&gt;. The Cell objects
are wired together into a sort of mesh network. Instead of growing it
wraps around on the sides.
&lt;/p&gt;
&lt;p&gt;
It takes up to four arguments right now, with three types of cells,
&lt;code&gt;basic&lt;/code&gt;, implementing the basic Conway's Game of Life,
&lt;code&gt;growth&lt;/code&gt;, which is a cell that matures over time, and
&lt;code&gt;random&lt;/code&gt; which mixes both types together (seen in the
screenshot). The arguments work as follows,
&lt;/p&gt;
&lt;pre&gt;
java -jar GoL.jar [&amp;lt;cell type&amp;gt; [&amp;lt;width&amp;gt; &amp;lt;height&amp;gt; [&amp;lt;cell pixel width&amp;gt;]]]
&lt;/pre&gt;
&lt;p&gt;
I may look into extending this to do some things beyond simple
cellular automata.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Tweaking Emacs for Ant and Java</title>
    <link>http://nullprogram.com/blog/2009/12/06</link>
    <description>&lt;!-- 6 December 2009 --&gt;
&lt;p&gt;
Developing C in Emacs is a real joy, and it's mostly thanks to the
compile command. Once you have your Makefile -- or SConstruct or
whatever build system you like -- setup and you want to compile your
latest changes, just run &lt;code&gt;M-x compile&lt;/code&gt;, which will run your
build system in a buffer. You can then step through the errors and
warnings with &lt;code&gt;C-x `&lt;/code&gt;, and Emacs will take you to
them. It's a very nice way to write code.
&lt;/p&gt;
&lt;p&gt;
I use the compile command so much that I bound it to &lt;code&gt;C-x
C-k&lt;/code&gt; (&lt;code&gt;C-k&lt;/code&gt; tends to be part of compile key
bindings),
&lt;/p&gt;
&lt;pre&gt;
(global-set-key &lt;span class=&quot;string&quot;&gt;&quot;\C-x\C-k&quot;&lt;/span&gt; 'compile)
&lt;/pre&gt;
&lt;p&gt;
Until recently, I didn't have as nice of a setup for Java. Since they
generally force offensive IDEs onto me at work this wasn't something I
needed yet anyway, but &lt;i&gt;I&lt;/i&gt; get to choose my environment on a new
project this time. If you're using Makefiles for some reason when
building your Java project, it still works out fairly well because
they're usually called recursively. It gets more complicated with &lt;a
href=&quot;http://ant.apache.org/&quot;&gt;Ant&lt;/a&gt;, where there is only one
top-level build file. Emacs' compile command only runs the build
command in the buffer's current directory.
&lt;/p&gt;
&lt;p&gt;
I know three solutions to this problem. One is to provide the build
file's absolute path when &lt;code&gt;compile&lt;/code&gt; asks for the command
with the &lt;code&gt;-buildfile&lt;/code&gt; (&lt;code&gt;-f&lt;/code&gt;) option. You only
need to type it once per Emacs session, so that's not &lt;i&gt;too&lt;/i&gt; bad.
&lt;/p&gt;
&lt;pre&gt;
ant -emacs -buildfile /path/to/build.xml
&lt;/pre&gt;
&lt;p&gt;
It's not well documented, but there is a &lt;code&gt;-find&lt;/code&gt; option
that can be given to Ant that will cause it to search for the build
file itself. This is even nicer than the previous solution. Just
remember to place it last, unless you give it the build filename
too. For example, if you wanted to run the &lt;code&gt;clean&lt;/code&gt; target,
&lt;/p&gt;
&lt;pre&gt;
ant -emacs clean -find
&lt;/pre&gt;
&lt;p&gt;
To keep the actual call as simple as possible, I wrote a wrapper for
&lt;code&gt;compile&lt;/code&gt;, and put a hook in &lt;code&gt;java-mode&lt;/code&gt; to
change the local binding. The wrapper, &lt;code&gt;ant-compile&lt;/code&gt;,
searches for the build file the same way &lt;code&gt;-find&lt;/code&gt; would do.
&lt;/p&gt;
&lt;pre&gt;
(&lt;span class=&quot;keyword&quot;&gt;defun&lt;/span&gt; &lt;span class=&quot;function-name&quot;&gt;ant-compile&lt;/span&gt; ()
  &lt;span class=&quot;string&quot;&gt;&quot;Traveling up the path, find build.xml file and run compile.&quot;&lt;/span&gt;
  (interactive)
  (&lt;span class=&quot;keyword&quot;&gt;with-temp-buffer&lt;/span&gt;
    (&lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt; (and (not (file-exists-p &lt;span class=&quot;string&quot;&gt;&quot;build.xml&quot;&lt;/span&gt;))
                (not (equal &lt;span class=&quot;string&quot;&gt;&quot;/&quot;&lt;/span&gt; default-directory)))
      (cd &lt;span class=&quot;string&quot;&gt;&quot;..&quot;&lt;/span&gt;))
    (call-interactively 'compile)))
&lt;/pre&gt;
&lt;p&gt;
So I can transparently keep using my muscle memory compile binding, I
set up the key binding in a hook,
&lt;/p&gt;
&lt;pre&gt;
(add-hook 'java-mode-hook
          (&lt;span class=&quot;keyword&quot;&gt;lambda&lt;/span&gt; () (local-set-key &lt;span class=&quot;string&quot;&gt;&quot;\C-x\C-k&quot;&lt;/span&gt; 'ant-compile)))
&lt;/pre&gt;
&lt;p&gt;
Voila! Java works looks a little bit more like C.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>First Maryland Snow of 2009</title>
    <link>http://nullprogram.com/blog/2009/12/05</link>
    <description>&lt;!-- 5 December 2009 --&gt;
&lt;p&gt;
Yesterday was a slightly chilly day, in the mid 50s (Fahrenheit), so
when my officemate said we were getting snow I thought she was
kidding. Well, today we woke up to this winter wonderland,
&lt;/p&gt;
&lt;p class=&quot;center&quot;&gt;
  &lt;video src=&quot;/video/snow-2009.ogv&quot; controls
         poster=&quot;/video/snow-2009.jpg&quot;&gt;
    Sorry, you're browser does not support HTML 5 and Ogg Theora. Get
    with the times! :-) While you're waiting for your browser to
    update you can &lt;a href=&quot;/video/snow-2009.ogv&quot;&gt;download the
    video&lt;/a&gt;.
  &lt;/video&gt;
&lt;/p&gt;
&lt;p&gt;
My wife leapt for her camera and filmed that as soon as she realized
what was going on. We had much more than that by late afternoon.
According to the &lt;a
href=&quot;http://www.baltimoresun.com/news/maryland/bal-md.weather05dec05,0,7717319.story&quot;&gt;
Baltimore Sun&lt;/a&gt; it has snowed on December 5th for six of the last
eight years, and we don't get much snow around here. My only wish
would be for this to have happened on a weekday. I work for a
university, and educational organizations tend to fold and give snow
days really easily. This would probably have given me a nice paid day
off!
&lt;/p&gt;</description>
  </item>
  </channel>
</rss>