[Small-cl-src] m-v-b* and d-b* (auto-ignoring arguments called _)
Andreas Fuchs
asf at boinkor.net
Tue Nov 2 21:28:50 UTC 2004
;;; Hi,
;;;
;;; I hope this code makes a few functions (like decode-universal-time)
;;; more useful. Each of these functions replaces variables with a
;;; symbol-name of _ with a (declare (ignore))d gensym.
;;;
;;; I'm sure everybody has already written something similar.
;;; "Somebody should write a CLRFI for that" (-:
(require :iterate)
;; Yeah, sorry.. the solution using LOOP was ugly as hell.
(defun replace-binds (binds)
(iterate (for bind in binds)
(typecase bind
(cons
(multiple-value-bind (result* ignore*) (replace-binds bind)
(collecting result* into result)
(appending ignore* into ignore)))
(t
(if (string-equal bind '_)
(let ((sym (gensym)))
(collect sym into result)
(collect sym into ignore))
(collect bind into result))))
(finally (return (values result ignore)))))
(defmacro destructuring-bind* (bind-list obj &rest body)
(multiple-value-bind (binds ignores) (replace-binds bind-list)
`(destructuring-bind ,binds ,obj
(declare (ignore , at ignores))
, at body)))
(defmacro multiple-value-bind* (bind-list obj &rest body)
(multiple-value-bind (binds ignores) (replace-binds bind-list)
`(multiple-value-bind ,binds ,obj
(declare (ignore , at ignores))
, at body)))
;;; Have fun,
--
Andreas Fuchs, <asf at boinkor.net>, asf at jabber.at, antifuchs
More information about the Small-cl-src
mailing list