bug, intended behavior or am I wrong?

Anonymous
2009-05-03
2012-11-23
  • Anonymous

    Anonymous - 2009-05-03

    Consider the following rule:

    (defclass Man (is-a USER)
       (multislot friends))

    (defrule rule1
      (object (is-a Man) (friends ?f))
       =>
      (printout t "This guy has friends." crlf))

    ***********************************
    Then I create a Man:

    (make-instance jack of Man)  ;I did not mention the friends field

    This rule will not pick up this instance of Man. This only happens with
    multislots, not slots.

    Also, if I create the instance like this:
    (make-instance jack of Man (friends nil))
    THEN the rule picks up the instance.

    Am I missing something here?

     
    • Gary Riley

      Gary Riley - 2009-05-03

      The default value for a multifield slot is a multifield with no values. Your pattern, (friends ?f), requires one and exactly one value in order to be matched, so the behavior you're seeing is correct since calling make-instance with no values placed in friends will use the default value. For your pattern to work correctly based on the print statement in the rule it should be (friends ? $?) which will match any Man who has one or more friends.

       

Log in to post a comment.