X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fkmr-mop.lisp;h=f35528272204bdd94c4749ef483d69639a3795bd;hp=75ccb5eaa2eacf919f75f5848f66914bd55da5a3;hb=HEAD;hpb=47d5ae2b1454553fa6d71c08862c7dfc5df97a92 diff --git a/sql/kmr-mop.lisp b/sql/kmr-mop.lisp index 75ccb5e..f355282 100644 --- a/sql/kmr-mop.lisp +++ b/sql/kmr-mop.lisp @@ -66,14 +66,28 @@ #+mop-slot-order-reversed (reverse (class-direct-slots class)) #-mop-slot-order-reversed (class-direct-slots class)) -(defun find-class-slot-by-name (class slot-name &optional direct?) +(defun find-slot-if (class predicate &optional direct? recurse?) "Looks up a direct-slot-definition by name" (setf class (to-class class)) - (find (to-slot-name slot-name) - (if direct? - (ordered-class-direct-slots class) - (ordered-class-slots class)) - :key #'slot-definition-name)) + (labels ((find-it (class) + (let* ((slots (if direct? + (ordered-class-direct-slots class) + (ordered-class-slots class))) + (it (find-if predicate slots))) + (or it + (when recurse? + (loop for sup in (class-direct-superclasses class) + for rtn = (find-it sup) + until rtn + finally (return rtn))))))) + (find-it class))) + +(defun find-slot-by-name (class slot-name &optional direct? recurse?) + "Looks up a direct-slot-definition by name" + (setf class (to-class class) + slot-name (to-slot-name slot-name)) + (find-slot-if class (lambda (slot-def) (eql (to-slot-name slot-def) slot-name)) + direct? recurse?)) ;; Lispworks has symbol for slot rather than the slot instance (defun %svuc-slot-name (slot)