syntax-error - 有条件的情况下如何正确使用加法?片段

标签 syntax-error exists addition clips

我正在尝试检查汽车前面是否有任何障碍物。假设汽车在位置“2”。我的目标是检查位置“3”处是否有障碍物。
可能没有明确的障碍事实,这意味着在特定位置没有障碍。我检查使用是否存在有条件。但是在规则 r6 中,对于这部分(+?location_car 1),我收到CLIPS语法错误 [PRNTUTIL2] 。如果我放弃添加,它会起作用。我可以使用什么替代方法?或者我只是缺少一些语法方面的东西?

  (deftemplate car
  (slot location)
)
(deftemplate obstacles
  (slot location) ; location of road segment
  (slot tlights) ; number of red traffic lights
  (slot cars) ; number of cars which have priority drive through
  (slot pedestrians) ; number of pedestrians crossing the road
  (slot spec_service) ; number of spec service vehicles passing by
)

(deffacts faktu-inicializavimas
 (car (location 0))
 (obstacles (location 9) (tlights 1) (cars 2) (pedestrians 5) (spec_service 2))
)

(defrule r6 "Drive to location"
  ?fact-id1 <- (car (location ?location_car))
  (or
    (exists (obstacles (location (+ ?location_car 1)) (tlights 0) (cars 0) (pedestrians 0) (spec_service 0)))
    (not
      (exists (obstacles (location (+ ?location_car 1)) ))
    )
  )
=>
 (printout t "Drive to location")
 (modify ?fact-id1 (location (+ ?location_car 2)))
)

最佳答案

使用返回值约束(等号=)将字段约束为函数调用的返回值。

(defrule r6 "Drive to location"
  ?fact-id1 <- (car (location ?location_car))
  (or
    (exists (obstacles (location =(+ ?location_car 1)) 
                       (tlights 0) 
                       (cars 0) 
                       (pedestrians 0) 
                       (spec_service 0)))
    (not
      (exists (obstacles (location =(+ ?location_car 1)) ))
    )
  )
=>
 (printout t "Drive to location")
 (modify ?fact-id1 (location (+ ?location_car 2)))
)

关于syntax-error - 有条件的情况下如何正确使用加法?片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42321832/

相关文章:

subquery - 选择多个字段不在子查询中的位置(不包括连接)

c++ - 检查 Unix 中是否存在目录(系统调用)

jQuery .add 方法

mysql - 通过 Procedure 在 MySQL 中进行算术运算

MySQL:使用 "two halves"方法查找中位数

scheme - 方案功能(DrRacket)

php - PHP解析/语法错误;以及如何解决它们

php - 更改服务器,并获取SyntaxError : JSON.parse: unexpected character parsererror

MySQL 5.7 : UNIQUE and exists

c - 在C中添加和打印多个字符