Note: I wrote this a while ago and never proof read / published it, so this patch was actually included in Bind a while ago.
I finally got around to trying out Gary King’s Metabang-Bind library. There has been a bit of grumbling around the office about how I might be doing it wrong, if I need to bind so many variables that I need this library. I felt this at first as well, but to some extent, the things I was working on pretty were imperative. I am writing a replacement for our invoicing program and had about twenty bindings in a row. I found the code to be neater and easier to read after switching to bind so I feel that this was a win overall.
After using it a bit, I found a few things that I wanted to add. It was pleasing to discover that the code was very easy to extend. To add a new binding pattern was simply a matter of specializing a new method based on the first token in the binding form.
The first change I made was that, when binding accessors I wanted to be able to write to the variable and have that effect the values in the object. The current binding scheme for accessors converted to a
let* form. My change simply made the accessors bind using a
with-accessors form instead of the
let*. The older form involving the
let* is still available using the
:accessors-read-only symbol instead of
:accessors. The following is the lift unit test demonstrating this patch in action:
| 1: (addtest (test-classes)
4: (bind ((obj (make-instance 'metabang-bind-class-2
5: :a 1 :b 2 :c 3 :d 4 :e 5))
6: ((:accessors a c e) obj))
7: (setf a :a c :c)
8: (list (e obj) (c obj) (a obj)))
9: '(5 :c :a) :test 'equal))