One of the advantages of this automatic case conversion is that it allows us to use case as syntactic markers.
Here's a simple example (ignore the non idiomatic use of CL).
(defun filter (test list)
(let ((result ()))
(dolist (elt list result)
(when (funcall test elt)
(push elt result)))))
Did you notice the return form?
This happens to be one of those constructs that is quite easy to overlook when reading through code, it doesn't happen often but it does happen[3].
However, if we change it to this.
the result form 'leaps' out of the page which makes it very difficult to miss.
(defun filter (test list)
(let ((result ()))
(dolist (elt list RESULT)
(when (funcall test elt)
(push elt result)))))
It's the code equivalent of wearing a silly hat.
---
1: Stranger, as in, 'This isn't like C/Java/Python/Ruby'.
2: This is only the default and can be changed using readtable-case
3: Well it happens to me, ok.
2 comments:
I do that one myself from time to time. :)
Also, over the years I've been switching between just about every iteration tool available in the CL space, except do which I dismissed early. This year I decided to sit down and write a general one that lessens the impedance I think about iteration when coding.
Shortly into it, I realized I was reinventing the one construct I dismissed very early on: do Hehe.
Post a Comment