map-bind
An embarassingly trivial (but crucial) visual macro in Quicklisp.
| Project Type | Library | |
|---|---|---|
| Programming language | Common Lisp | |
| Status | Ready-to-use | |
| License | Public Domain | |
| Library type | Visual macro | |
| Project complexity | Embarassingly trivial | |
| Latest release | Version | 1.0 |
| Date | 8 aug 2012 | |
|
Quicklisp
(Aug 2012 dist and later) |
Status | Available |
| Version | Latest | |
External library pages
| Depends on | Depended on by | |
|---|---|---|
| Directly | Nothing | |
| Indirectly | Nothing | Nothing |
map-bind is a macro that allows visual grouping of variables with their corresponding values (not necessarily 1:1) in calls to mapping operators when using an inline lambda. It does so in a way that automatically supports virtually every existing and future mapping operator, all lambda list keywords and funcall/apply/multiple-value-call variations.
It does all this with a surprisingly simple implementation!
Here's an example designed to show many features at once:
(color key: prologue arguments values lambda-body)
(map-bind (multiple-value-call #'map 'vector)
((symbol #(a b c))
(number '(1 2 3))
((&rest others &key &allow-other-keys) (values '(d e f) #(4 5 6)))
((&aux (plus-ten (+ number 10)))))
(list (1- number) symbol plus-ten (reverse others)))
==
(multiple-value-call #'map 'vector
(lambda (symbol number
&rest others &key &allow-other-keys
&aux (plus-ten (+ number 10)))
(list (1- number) symbol plus-ten (reverse others)))
#(a b c)
'(1 2 3)
(values '(d e f) #(4 5 6)))
=>
#((0 A 11 (4 D)) (1 B 12 (5 E)) (2 C 13 (6 F)))
To use map-bind, simply (:import-from #:map-bind #:map-bind). Don't (:use)!