I use Fish as my command-line shell. But when I feel the need to write a shell script these days I use Scheme, via scsh. It has been a while since I’ve written Scheme (or any Lisp) on a regular basis, and so I find myself typing down some dumb, novice mistakes. And tonight I want to share one.
Spot the Problem
Here is a piece of a script I use to update certain software, namely fetching updates from repositories and compiling them. See if you notice the problem:
(for-each (lambda (dir) (update-git-sub-directories dir)) directories-with-git-repositories)
See the issue? Keep in mind that
for-each calls a given function (here an anonymous function) for each element of a list. Think about that until you see the facepalm-quality redundancy.