do-children macro.
Thu Aug 23 10:59:58 PDT 2007 Ryszard Szopa <ryszard.szopa@gmail.com>
* do-children macro.
diff -rN -u old-mop-utils/mop-utils.lisp new-mop-utils/mop-utils.lisp
--- old-mop-utils/mop-utils.lisp 2014-07-30 16:17:42.000000000 -0700
+++ new-mop-utils/mop-utils.lisp 2014-07-30 16:17:42.000000000 -0700
@@ -4,7 +4,8 @@
(defpackage mop-utils
(:documentation "A set of Metaobject Protocol utilities.")
(:use :cl #+sbcl :sb-mop #-sbcl :closer-mop)
- (:export #:defmetaclass #:class-name-of #:slots-of #:slot-names-of #:get-slot-of-by-name #:get-slot-by-name))
+ (:export #:defmetaclass #:class-name-of #:slots-of #:slot-names-of #:get-slot-of-by-name #:get-slot-by-name
+ #:do-children))
(in-package :mop-utils)
@@ -91,3 +92,10 @@
(defun get-slot-of-by-name (object name)
(get-slot-by-name (class-of object) name))
+
+(defmacro do-children ((var class-name) &body body)
+ "For every subclass of class named by CLASS-NAME, execute BODY with VAR bind to it."
+ (let ((children (class-direct-subclasses (find-class class-name))))
+ `(loop :for ,var :in ',children
+ :do ,@body)))
+
\ No newline at end of file