Posts Tagged ‘CraftsmanGuild’

Here Comes Clojure: A Clojure Talk in Clojure

April 6th, 2011 5 comments

TL;DR: I did a talk on Clojure and wrote the slides in Clojure. Code here.

Edit: Fixed apostrophes. That’s embarrassing.

On kinda short notice I found out I was giving a talk on Clojure at this week’s CraftsmanGuild meeting in Ann Arbor. I’m not an expert, but “in the land of the blind, the one-eyed man is king” or something, so I was happy to do it. CraftsmanGuild is low pressure and fun.

So, I fired up PowerPoint, wrote a title slide, and then stared at the screen for a bit. This is no fun. Then it was the kids’ bedtime, which means I got to sit in my daughter’s room for a bit and just ponder. Like Hammock Driven Development, I guess. And as I sat there, in the glow of the nightlight, I got it: Why not implement my talk in Clojure, driven by some simple vim macros? It’s either brilliant, or really stupid.

If anything, the benefits outweighed the risks:

  • Practice Clojure while preparing my talk
  • Practice Vim while preparing my talk
  • No PowerPoint

The main risk was totally bombing in front of a friendly audience that’s just there to learn and have fun. Not too scary.

Here’s a screenshot of the title “slide”:

The implementation is super simple. Basically just a vector of strings and a current atom which points at the current slide. The advance! function moves the pointer, formats the slide (nice ascii borders and padding) and prints it.  It’s super simple, and can certainly be written better. I ran all of this in a VimClojure REPL set up as described in a previous post. There were a few cool things about this:

  • I got syntax highlighting of sample code (and admittedly, the rest of the text) for free.
  • I could immediately type examples or elaborate ideas directly in the REPL without leaving my “slides”.
  • I could evaluate code samples right from the slide and expand on them live.

I hacked (I mean they’re really kludgy) together some simple vim macros to:

  • Reload the presentation code
  • Go back to the beginning
  • Advance to the next slide
  • Evaluate the form under the cursor in the REPL. This was slightly tricky because it had to strip out the slide “borders” first.

Overall, I think the effect was pretty cool. Everything ran well, with the major problem being that the projector’s red wasn’t working so it was hard to see some of the text. Oh, and at one point I accidentally hit my caps lock with the usual confusion that accompanies it. Bygones. The actual content was probably the weakest part of the talk, but not terrible. Passable for two nights prep.

Here’s one last screenshot showing some syntax highlighting and simple ascii diagramming:

The code for the talk is all up on github: Note that vim isn’t required. It will run in a normal REPL, it just won’t look as nice. And, of course, I’m sure something much more impressive is already built-in to Emacs :)

Categories: clojure, vim Tags: , ,