I have several predicate/templates that share certain behavior.  I'd
like to exopress this through shared code.  FOr example: I have two
templates of the form

    (same-side ?s1 ?s2)     and
    (same-face ?f1 ?f2)

I can't just merge these into one "equality" template because there
are other rules which concern one but not the other.  Also I want to
maintain type distinction.

I would like to define rules which state that these templates share
the same properties as eqauality:

    (do-backward-chaining same-side)

    (defrule same-side-reflexive
      (test (eq ?a ?b))
      =>
      (assert (same-side ?a ?b)))

    (defrule same-side-symetric
      (same-side ?side1 ?side2)
      =>
      (assert (same-side ?side2 ?side1)))

    (defrule same-side-transitive
      (same-side ?side1 ?side2)
      (same-side ?side2 ?side3)
      =>
      (assert (same-side ?side1 ?side3)))

and similarly for same-face:

    (do-backward-chaining same-face)

    (defrule same-face-reflexive
      (test (eq ?a ?b))
      =>
      (assert (same-face ?a ?b)))

    (defrule same-face-symetric
      (same-face ?face1 ?face2)
      =>
      (assert (same-face ?face2 ?face1)))

    (defrule same-face-transitive
      (same-face ?face1 ?face2)
      (same-face ?face2 ?face3)
      =>
      (assert (same-face ?face1 ?face3)))

Is there some way that I can define these "duplicated" rules only once
and then tell Jess that those rules apply to the same-face and
same-side templates?

I'd know how to achieve something like this if the CommonLisp
macroexpander were abvailable.  Is there some way of doing this in
Jess?  For example, can I use a variable in the first element of a
template:

    (defrule template-like-equals
      (equality-template ?template-name)
      =>

      (do-backward-chaining ?template-name)

      (defrule (sym-cat ?template-name "-reflexive")
        (test (eq ?a ?b))
        =>
        (assert (?template-name ?a ?b)))

      (defrule (sym-cat ?template-name "-symetric")
        (?template-name ?face1 ?face2)
        =>
        (assert (?template-name ?face2 ?face1)))

      (defrule (sym-cat ?template-name "-transitive")
        (?template-name ?face1 ?face2)
        (?template-name ?face2 ?face3)
        =>
        (assert (?template-name ?face1 ?face3)))
      )

    (deffact (equality-template same-side))
    (deffact (equality-template same-face))

I havn't tried this yet.  Would it work?  Is there a better way?



--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to