CLIPS> (defclass A (is-a USER))
CLIPS> (defclass B (is-a A))
CLIPS> (defclass C (is-a B))
CLIPS> (defclass D (is-a C))
CLIPS> (defclass E (is-a D))
CLIPS> (defclass X (is-a USER))
CLIPS> (defclass Y (is-a X))
CLIPS> (defclass Z (is-a Y))
CLIPS> (defclass Q (is-a E Z))
CLIPS>
(deffunction class-superclasses-breadth* (?classes $?chain)
(if (= (length$ ?classes) 0) then (return ?chain))
(bind ?next-classes (create$))
(progn$ (?c ?classes)
(bind ?add (class-superclasses ?c))
(progn$ (?a ?add)
(if (not (member$ ?a ?chain))
then
(bind ?chain (create$ ?chain ?a))
(bind ?next-classes (create$ ?next-classes ?a)))))
(bind ?chain (class-superclasses-breadth* ?next-classes ?chain))
(return ?chain))
CLIPS>
(deffunction class-superclasses-breadth (?class)
(return (class-superclasses-breadth* (create$ ?class))))
CLIPS> (class-superclasses-breadth Q)
(E Z D Y C X B USER A OBJECT)
CLIPS>
On Mar 31, 6:10 pm, baylor <
bayl...@yahoo.com> wrote:
> > How are you programatically walking the hierarchy to get a
> > match in A?
>
> i'm trying to figure out what my options are. The easiest was
>
> CLIPS> (class-superclasses Q inherit)
>
> which gives me the list of superclasses as an array, so i can pop one off, check it and if it fails, try the next. The issue here is that class-superclasses returns the classes in depth order - (C B A Z Y X). So A (great grandfather) would match before Z (direct parent)
>
> i have a different solution that i think works where i call class-superclasses without the inherit flag, post those as facts and then let the rule engine run through one or two dozen rules until it finds a match but the code seems... big and complicated and possibly error prone (in CLIPS i'm never quite sure when i get good results because i wrote the rules correctly and when it's an artifact of my build and machine, especially when i use complexity for conflict resolution and the all the facts go through the same rule, hence equal number of antecedents and no guarantee of evaluation order under complexity)
>
> i've considered writing a foreach loop to get the immediate parents and then calling the function on those but the most obvious recursive solution also results in a depth ordering, so i need to think of a way to handle that
>
> With enough thought and code, i can get the ordering i want, but i want to make sure i'm not missing some really simple way, like an alternative to class-superclasses or a flag i didn't notice
>
> -b
>
> --- On Tue, 3/31/09, CLIPS Support <
gdronline2...@swbell.net> wrote: