[英]Avoid pattern matching (errors) until a slot is set correctly
規則R_blup
的LHS包含
(test (>= ?s2 2))
也就是說,它檢查?s2
是否大於或等於?s2
對應於名為s2
的實例插槽。
不幸的是,我得到了錯誤
Function >= expected argument #1 to be of type integer or float
問題是我的代碼在設置參數#1之前,即在將s2
設置為整數或浮點值之前執行了(test ...
應該在python調用中將s2
設置為整數。由另一個規則R_blah
觸發。
該錯誤在屬於另一個規則R_xyz
的另一個python調用的中間觸發。 此python調用通過clips_instance.Slots["slot_name"] = some_value
修改實例。
通常如何處理? 我看到了我不太喜歡的三種解決方案:
s2
的默認(整數)值。 (test ...
以首先檢查nil
。 s2
不再nil
是否有可能嘗試/排除/傳遞錯誤?
使用函數object-pattern-match-delay延遲模式匹配,以針對一系列更改創建原子操作:
CLIPS> (defclass POINT (is-a USER) (slot x) (slot y))
CLIPS>
(defrule check
(object (is-a POINT) (x ?s2))
(test (>= ?s2 2))
=>)
CLIPS> (make-instance [p1] of POINT)
[ARGACCES5] Function >= expected argument #1 to be of type integer or float
[DRIVE1] This error occurred in the join network
Problem resides in associated join
Of pattern #1 in rule check
[p1]
CLIPS> (agenda)
CLIPS>
(object-pattern-match-delay
(make-instance [p2] of POINT)
(make-instance [p3] of POINT)
(send [p2] put-x 3)
(send [p3] put-x 0))
0
CLIPS> (agenda)
0 check: [p2]
For a total of 1 activation.
CLIPS>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.