0

规则的 LHSR_blup包含

(test (>= ?s2 2))

也就是说,它检查是否?s2大于或等于 2。?s2对应于名为 的实例槽s2

不幸的是,我得到了错误

Function >= expected argument #1 to be of type integer or float

问题是我的代码(test ...在我可以设置参数#1 之前执行,即在我可以设置s2为整数或浮点值之前。s2应该在由另一个规则触发的 python 调用中设置为整数R_blah

该错误是在属于另一个 rule 的另一个 python-call 中间触发的R_xyz。这个 python 调用通过clips_instance.Slots["slot_name"] = some_value.

这通常是如何处理的?我看到三个我不太喜欢的解决方案:

  1. 为 设置默认(整数)值s2
  2. 修改(test ...以首先检查nil
  3. 添加另一个检查/规则以等待s2不再nil

是否有可能尝试/排除/传递错误?

4

1 回答 1

1

使用函数 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> 
于 2017-04-27T16:45:54.107 回答