Writing Elisp Functions

John Kitchin is back with another in his series of videos comparing Python and Elisp programming. This time it’s about writing Elisp functions. Earlier, Kitchin made a video discussing how to write Python functions. This video is a followup that reimplements the Python functions in Elisp following the original implementation strategy as closely as possible.

The video mostly focuses on handling the function arguments. The canonical Elisp function using defun is pretty straightforward. You call the function by specifying each of the arguments listed in the function definition with the possible exception of optional arguments. There are no keywords. Keywords can be included if you use cl-defun to define the function. That enables certain Common Lisp additions including keywords.

At one point, Kitchin wants to test if every value of a list of boolean values is t. The natural way of doing that is

(apply #'and list-of-booleans)

but that doesn’t work because and is a macro, not a function. Kitchin couldn’t remember how to do it and ended up using the -all? predicate from the Dash library. I couldn’t remember either but I did remember writing about it years ago. It turns out that it was 10 years ago so no wonder I didn’t remember. You can read that post for a discussion of the issues and the standard Elisp way of performing an and or or on a sequence of values.

Kitchin says he’s trying to get his viewers to the point where they can begin writing their own Elisp applications. The video is 26 minutes so you’ll need to schedule some time but as always with Kithcin’s content, it’s worth your time.

This entry was posted in General and tagged , . Bookmark the permalink.