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

Martin Simmons martin at lispworks.com
Fri Nov 26 20:03:46 UTC 2010


>>>>> On Fri, 26 Nov 2010 14:36:57 +0100, Pascal Costanza said:
> 
> Hi,
> 
> 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)))))))))
> 
> Did anybody see anything similar before? Any suggestions for improvement?

I am confused about why guard has parens around it.  It might be better to
group the guard and the body like cond does, i.e.

(destructuring-bind ((&rest lambda-list) expression (guard &rest body)) first

Also the nesting of the multiple-value-binds in the expansion leads to
unexpected lexical scoping.  Maybe if you call it multiple-value-cond* ...

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/




More information about the pro mailing list