map-bind
2012-08-11
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 keywords and FUNCALL/APPLY/MULTIPLE-VALUE-CALL variations.
Author
Jean-Philippe Paradis <hexstream@gmail.com>
License
Public Domain
Project's home: http://www.hexstreamsoft.com/projects/map-bind/
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 keywords and FUNCALL/APPLY/MULTIPLE-VALUE-CALL
variations.
It does all this with a surprisingly simple implementation!
(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)))
This library is in the Public Domain.
See the UNLICENSE file for details.