Sunday, 10 February 2008

Case Conversion Considered Useful

One of the stranger[1] features of Common Lisp is that the CL reader, by default, will convert symbols to uppercase[2] which can be a little surprising to newcomers, and inevitably leads misconceptions regarding case (in)sensitivity.

One of the advantages of this automatic case conversion is that it allows us to use case as syntactic markers.

Here's a simple example (ignore the non idiomatic use of CL).

(defun filter (test list)
(let ((result ()))
(dolist (elt list result)
(when (funcall test elt)
(push elt result)))))

Did you notice the return form?
This happens to be one of those constructs that is quite easy to overlook when reading through code, it doesn't happen often but it does happen[3].

However, if we change it to this.

(defun filter (test list)
(let ((result ()))
(dolist (elt list RESULT)
(when (funcall test elt)
(push elt result)))))
the result form 'leaps' out of the page which makes it very difficult to miss.

It's the code equivalent of wearing a silly hat.

---

1: Stranger, as in, 'This isn't like C/Java/Python/Ruby'.
2: This is only the default and can be changed using readtable-case
3: Well it happens to me, ok.

Tuesday, 5 February 2008

The 'pre Arc' Arc

Seeing that arc is the word on everyones lips I thought I'd take a quick peek.

In Summary.
- data in the functional position is interesting.
- [] function syntax is neat (and almost as nice as the #L syntax in iterate)
- foo:bar for function composition reads quite nicely (once you get out of the CL mindset)

The rest is kind of 'meh' and then i realized, wait a second, a Lisp1 with more Lisp than Scheme and unhygienic macros,  I've seen that before and I had, it is called rep.  This is the Lisp that powers sawfish which (and someone correct me if I'm wrong) was the default window manager for GNOME for quite some time.

This was actually the Lisp that I cut my teeth on way back in 2001 (Grief, I can't believe it was that long ago)  and looking back on it brings back some fond memories and reminds me how full featured it was (especially for something at version 0.17), to list some of them:

  • Profiler
  • Module system (modelled on Scheme48)
  • Tail call elimination
  • Byte Compiled
  • First class Continuations
  • Regexes
  • Threading
  • Good access to OS 
  • Ability to load .so files
  • Bindings to mysql
  • Built in documentation via the ,desc operator

and Most importantly it has apropos, god knows why arc is missing this.