[pro] Chains of multiple-value-bind...

Faré fahree at gmail.com
Fri Nov 26 20:25:59 UTC 2010


On 26 November 2010 08:36, Pascal Costanza <pc at p-cos.net> wrote:
> I just hacked the following macro:
>
> (defmacro multiple-value-case (&body clauses)
>  (when clauses
>    (destructuring-bind (first &rest rest) clauses
>      (cond ((member (first first) '(t otherwise))
>             (when clauses (warn "Dead code: ~S." clauses))
>             `(progn ,@(rest first)))
>            (t (destructuring-bind ((&rest lambda-list) expression (guard) &rest body) first
>                   `(multiple-value-bind ,lambda-list ,expression
>                      (if ,guard (progn , at body)
>                        (multiple-value-case , at rest)))))))))
>
Your macro is leaking bindings like a sieve. The correct thing to do
is to destructure into gensyms, then rebind in the body (that can have
declarations of ignores).

> Did anybody see anything similar before? Any suggestions for improvement?
>
You could use fare-matcher which will do it all for you. Won't expand
to super-efficient code, unless your compiler is good at optimizing
linear lambdas away.

[ François-René ÐVB Rideau | Reflection&Cybernethics | http://fare.tunes.org ]
Anyone who says he can see through women is missing a lot. — Groucho Marx




More information about the pro mailing list