Matching hostnames with pcase in Elisp

I am not what you might call a “competent” Emacs Lisp programmer. More of a cargo-culter, really. But I’m trying to get better.

I create RubyTapas episodes across two different machines: “hazel”, my main development box, and “caroline”, my Windows video editing box. I needed to be able to recognize my synchronized episode directory on either machine, but the paths are different. So I wrote this:

This uses cond , the general-purpose conditional macro. It works, but it’s clunky. I keep repeating the string comparison code. As a Ruby programmer, I want something closer to Ruby’s pattern-matching case statement.

Today I read up on the pcase macro. It turns out it is both simpler and more powerful than I had realized. I haven’t used any of the power yet. But for this very trivial problem, it was as simple as replacing the equality tests with literal strings.

Easy, and nicer to look at!