|Programming language||Common Lisp|
|Library type||Wrapper macro|
|Project complexity||Embarassingly trivial|
|Date||23 oct 2012|
(Nov 2012 dist and later)
|Depends on||Depended on by|
enhanced-multiple-value-bind provides an enhanced
multiple-value-bind macro that adds support for lambda list keywords by expanding to a
multiple-value-call when necessary. This makes catching multiple-value
&key much more lightweight and convenient. A
multiple-value-&bind alias is supported.
- "unnatural" order of evaluation (skip over
lambda, evaluate values forms, then "come back" for
- significant extra indentation for the body.
&key are currently not being used a lot (as far as I know), but the awkwardness of using them up to now might have something to do with this state of affairs. Their usefulness and convenience should now be reassessed.
enhanced-mvb:multiple-value-bind is invoked without apparent lambda list keywords (symbols beginning with "&"), then it simply expands to
enhanced-mvb:multiple-value-bind(a b c) (values 1 2 3) ...) == (multiple-value-bind (a b c) (values 1 2 3) ...)
enhanced-mvb:multiple-value-bind(a b &rest rest) (values 1 2 3) ...) == (multiple-value-call (lambda (a b &rest rest) ...) (values 1 2 3))
An interesting consequence of this is that it's easy to accept an exact number of return values (though I'm not sure why you'd want to):
To use enhanced-multiple-value-bind, either refer to the provided
;; A bit long... (
enhanced-multiple-value-bind:multiple-value-bind(x y &rest others) (values 1 2 3 4) (values (* x y) others)) → 2, (3 4) ;; Much more managable package nickname. (
enhanced-mvb:multiple-value-bind(x y &rest others) (values 1 2 3 4) (values (* x y) others)) → 2, (3 4)
enhanced-multiple-value-bind also exports
multiple-value-&bind, with exactly the same functionality, so you can
(:import-from #:enhanced-multiple-value-bind #:multiple-value-&bind) in your
defpackage instead if you want.