blogroll tags

Lisping: IRC bots are fun

A wee while ago, I decided to learn a lisp. Randomly, my lisp of choice was Common Lisp. (though I will probably have a look at Scheme sooner or later) As if a new programming language wasn't enough, I also started using GNU Emacs (rather than my previous absolute favourite Vim) for editing the code... Why ? SLIME. Implementation-wise, I have used GNU CLISP (love it), Steel Bank Common Lisp (SBCL, quite nice) and GCL (rather pointless).

Of course, you cannot really learn a programming language without programming with it. Back in the day, I used the BWInf competition to learn the adorable Python language (along with a book), and this time, I solved a part of this years' BWInf round 1 in Common Lisp for starters. But, more importantly, as it was more fun and I can publish the code, I have written a bare-bones IRC bot in lisp using the CL-IRC library (which is very lacking in documentation, but both the IRC protocol and the library source code are open, so that wasn't a great problem).

You can get the code via Mercurial.

There is really only one aspect of the implementation worth noting here: the command-creation macros. Not really spectacular, but rather lispy, I'd say.

Instead of

(defun blah-command (connection source channel text)
  ; make sure the user is logged in
  ; parse the text into useful chunks
  ; more ))) than cool
)
(setf \*commands* (cons (list "blah" #'blah-command
                             "blah documentation) \*commands* ))

You write

(auth-irc-command admin "blah" (connection source channel) (arg1 arg2 arg3)
  ; get stuff done
)

etc.

Macro definitions are here.

:
:
:
: