Some Emacs Lisp exercises

1. Background: emacs.london

Since mid-last year I've been helping to organise a monthly Emacs event. It's a pretty low-key affair: we hang out in a room, sometimes do hands-on coding, sometimes share things on a screen, and then sometimes go to the pub afterwards.

Our usual format doesn't include speakers. This is partly because the best part of the meetup for us is meeting other attendees - presentations can be hit-or-miss. But it's also because it's a lot of work to arrange speakers for a monthly event, and a low-maintenance format means we can reliably keep it running.

Sometimes though, it can be too unstructured, and it would be nice to be given some direction on what to work on. We thought it would be fun to write some Emacs Lisp exercises to help with these situations, in the spirit of 4clojure.

2. The exercises

You can find the most recent exercises on at https://emacs.london/dojo.html. They're written as a single org-mode file, which you can get directly from github.

3. How it works

The idea is similar to the 4clojure exercises: you should fill in the function labelled __, so that when you execute it, the Pass: message shows t.

Here's the very first exercise. You just have to write a function that transforms the given string into uppercase:

(defun __ (s))

(let* ((result (__ "helloworld"))
       (pass (string= result "HELLOWORLD")))
  (format "Pass:%S\n%S" pass result))

The above code snippet can be executed in org-mode by pressing C-c C-c. When you do this, you'll see the results message added to the buffer:

: Pass:nil
: nil

The Pass:nil indicates that the test failed. The second line shows us the value that our function returned - in this case also nil.

Let's plug in a solution that uses the standard upcase function:

(defun __ (s)
  (upcase s))

(let* ((result (__ "helloworld"))
       (pass (string= result "HELLOWORLD")))
  (format "Pass:%S\n%S" pass result))

Now on execution we see:

: Pass:t

This time we're good.

4. You can contribute on on github

We're still in the early stages of building these materials - we may or may not find them useful over time. More exercises would be welcome though, and I'm sure there are some easy improvements or mistakes that can be corrected.

If you're interested in any of this then you'll be very welcome at the meetup.