问题
I need to check the existence of a value for an o'bject's property in a LHS.
(defrule check-property
?room <- (object (is-a ROOM))
(integerp (send ?room get-property)) ; #1
=>
(printout ?*debug-print* "Room " ?room " has property" crlf))
But it seems to me that #1 is not valuated in LHS. Instead if I put it in RHS, it returns TRUE. Where am I wrong?
Thx, Nic
回答1:
Use the test conditional element to evaluate an expression in the LHS of a rule:
(defrule check-property
?room <- (object (is-a ROOM))
(test (integerp (send ?room get-property)))
=>
(printout ?*debug-print* "Room " ?room " has property" crlf))
It's better to explicitly retrieve the slot value by matching it rather than using the slot accessor as this will cause the condition to be reevaluated whenever the slot value changes:
(defrule check-property
?room <- (object (is-a ROOM)
(property ?property))
(test (integerp ?property))
=>
(printout ?*debug-print* "Room " ?room " has property" crlf))
来源:https://stackoverflow.com/questions/37121490/checking-a-object-property-in-lhs