You could use either a defrule or a defquery to do it; the difference
depends on the context in which you want to use it. If you need to
write procedural code that iterates over all the matching objects,
then use a defquery. If you want to have a rule fire for each match,
use a defrule. Both the query and rule below can find all pairs of
objects that have the same time. We assume the hashCode values are
distinct and use them to order the results, otherwise you'll get both
(a,b) and (b,a) as separate matches.
(defquery query
(declare (variables))
(myClass (timeOfDay ?t) (OBJECT ?o))
(myClass (timeOfDay ?t) (OBJECT ?p&~?o))
(test (< (call ?o hashCode) (call ?p hashCode))))
(defrule rule
(myClass (timeOfDay ?t) (OBJECT ?o))
(myClass (timeOfDay ?t) (OBJECT ?p&~?o))
(test (< (call ?o hashCode) (call ?p hashCode)))
=>
(printout t ?p " has the same time as " ?o crlf))
I think Ricardo Manuel Oliveira wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
>
>
> I trying to define a set of rules that will test facts.. with each
> other.. that is: I have a set of objects and I want to compare the
> properties of these objects with each other. For instance, if I have a
> class with a property timeOfDay, with the methods getTimeOfDay and
> setTimeOfDay defined, I would like to find out which obects have the same
> time... I can't seem to figure out how to do this using defrule or
> defquery... can anyone help?
>
> P.S.: hope I could explain my problem right :)
>
> --
> Cheers,
>
> -- Ricardo Manuel Oliveira
> -- FCT - University of Coimbra, Portugal
>
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list (use your own address!) List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------