How to test that a slot has no value

  • geneyop

    geneyop - 2014-04-15


    Using COOL, I try to define a rule, with the condition that no value has been set to a slot.
    Here is what I tried :

       (defclass MyClass
            (is-a USER)
            (role concrete)
            (single-slot LinkedTo
                (type INSTANCE)
                (create-accessor read-write)))

       (make-instance [a] of MyClass)
       (make-instance [b] of MyClass (LinkedTo [a]))

       (defrule PrintNotLinked
            ?obj <- (object (is-a MyClass) (LinkedTo nil))
            (printout t (instance-name ?obj) crlf)

    But I get the following error :

       [CSTRNCHK1] A literal restriction value found in CE #1 does not match the allowed types for slot LinkedTo.

    Can somebody help me ?

    Thank you

  • Gary Riley

    Gary Riley - 2014-04-16

    The defaulted value for a slot restricted to type INSTANCE or INSTANCE-NAME is the instance name [nil], not the symbol nil. You get an error using the value nil in the LinkedTo slot because symbol is not a valid type for that slot. If you replace nil with [nil], the rule will not generate an error:

    (defrule PrintNotLinked
       ?obj <- (object (is-a MyClass) (LinkedTo [nil]))
       (printout t (instance-name ?obj) crlf))
  • geneyop

    geneyop - 2014-04-16

    Thank you Gary.
    It works well indeed.


Log in to post a comment.