Kaz Kylheku
5/24/2016 3:42:00 PM
On 2016-05-24, Grumpus <grumpus@example.org> wrote:
> Kaz Kylheku wrote:
>
>> And it appears to reduce to the simple non-key case if you use a
>> fixed key, and use only that key in all the cases.
>
> If that's how destructuring-case *really* works, the docs aren't any
> good:
>
> The clause whose case-keys matches car of key, as if by case, ccase,
> or ecase, is selected, and FORMs are then executed with cdr of key
> is destructured and bound by the destructuring-lambda-list.
Hmm. I.e. when the routing takes place on the key, then exactly one
destructuring pattern is eligible, and must match the datum.
Thus it is not selection over destructuring cases at all.
Rather, indeed, it is nothing more than a syntactic sugar which
condenses the following pattern:
(ecase (car obj)
(<key1> (destructuring-bind <pattern1> (cdr obj)
code1 ...))
(<key2> (destructuring-bind <pattern2> (cdr obj)
code2 ...))
...
(<keyN> (destructuring-bind <patternN> (cdr obj)
codeN ...))
Except (one would hope) that obj is evaluated only once.
Someone was writing lots of code like the above and decided to
factor out the repetition of destructive-bind and related noise;
certainly a worthwhile macro. The name is just badly chosen; I'd call
the above case-bind or something.