Number equality test fails in CLIPS pattern matching?

后端 未结 3 2057
清歌不尽
清歌不尽 2021-01-25 10:02

I have this following rule in my CLIPS file:

(defrule check-final (declare (salience 12))
    ?scnt <- (set-count (value ?v) (class ?c))
    (test (= ?v ?*tot         


        
3条回答
  •  天涯浪人
    2021-01-25 10:37

    The most likely explanation is that at some point the equality test is being satisfied and then the value of the global is changed before the rule executes.

    CLIPS> (deftemplate set-count (slot value) (slot class))
    CLIPS> 
    (defglobal ?*total* = 0)
    CLIPS> 
    (defrule check-final (declare (salience 12))
        ?scnt <- (set-count (value ?v) (class ?c))
        (test (= ?v ?*total*))
        =>
        (printout T ?*total* " == " ?v crlf)
    )
    CLIPS> (bind ?*total* 9)
    9
    CLIPS> (assert (set-count (value 9) (class a)))
    
    CLIPS> (bind ?*total* 14)
    14
    CLIPS> (run)
    14 == 9
    CLIPS> (bind ?*total* 2)
    2
    CLIPS> (assert (set-count (value 2) (class b)))
    
    CLIPS> (bind ?*total* 5)
    5
    CLIPS> (run)
    5 == 2
    CLIPS> 
    

提交回复
热议问题