Wednesday, June 23, 2004

Learning Lisp

I've been learning Lisp - after all, it's not as if I have anything else to do. It's very different to any other programming language I've learnt, and in a way it's very cool. I especially like the feature that the language itself can be used to modify the language, but I haven't really got to the stage where I can make use of that yet. Today I wrote a program:

(defun countdown (&rest args)
  (let ((target (apply #'encode-universal-time args))
    (do ((finished nil)) (finished)
        (sleep 1)
        (setf left (- target (get-universal-time)))
        (if (< left 0)
            (setf finished t)
          (format t "~a:~a:~a~%"
                  (floor (/ left 3600))
                  (floor (/ (mod left 3600) 60))
                  (mod left 60))))))

I've been finding ANSI Common Lisp by Paul Graham very handy (once Amazon finally decided to deliver it), and I've been using SBCL as my compiler.

Update: The history of Lisp, for anyone who's interested.


Peter Brett said...

The difference between the macro capabilities in C++ and those in Lisp are like the difference between a horse-drawn cart and a Ferrari. I haven't been learning Lisp long enough to give a good example, but you get the idea.

Peter Brett said...

Broadly generalizing, programming languages come in two families nowadays: the 'C family' (C, C++, Java, PHP, C# etc) and the 'Lisp family' (Lisp, Scheme, Smalltalk). Once people get into programming in one style, they prefer to continue programming in that style, so people who start programming in C-like languages stay with them. And newbie programmers tend to be put off by Lisp's syntax (actually very simple - it just looks complicated).