插槽修改事件
Event on slot modification
我想知道在 CLIPS 中我是否可以将事件关联到插槽的修改上。
示例:
(defclass ROOM (is-a USER)
(slot id
(type SYMBOL))
(slot windows-status
(allowed-strings "open" "close")))
当 'windows-status' 值发生变化时,我想根据允许的字符串调用一些函数。
谢谢,
尼古拉
为插槽的 put- 方法使用之前、之后或周围的消息处理程序,您可以根据值从消息处理程序调用函数。
CLIPS> (clear)
CLIPS>
(defclass ROOM (is-a USER)
(slot id
(type SYMBOL))
(slot windows-status
(allowed-strings "open" "close")))
CLIPS>
(defmessage-handler ROOM put-id before (?value)
(printout t "put-id event " ?self:id crlf))
CLIPS>
(defmessage-handler ROOM put-windows-status before (?value)
(printout t "put-window-status event " ?self:windows-status crlf))
CLIPS> (make-instance [r1] of ROOM (id room1) (windows-status "open"))
put-id event nil
put-window-status event nil
[r1]
CLIPS> (send [r1] put-id room2)
put-id event room1
room2
CLIPS> (send [r1] put-windows-status "close")
put-window-status event open
"close"
CLIPS>
我想知道在 CLIPS 中我是否可以将事件关联到插槽的修改上。 示例:
(defclass ROOM (is-a USER)
(slot id
(type SYMBOL))
(slot windows-status
(allowed-strings "open" "close")))
当 'windows-status' 值发生变化时,我想根据允许的字符串调用一些函数。
谢谢, 尼古拉
为插槽的 put- 方法使用之前、之后或周围的消息处理程序,您可以根据值从消息处理程序调用函数。
CLIPS> (clear)
CLIPS>
(defclass ROOM (is-a USER)
(slot id
(type SYMBOL))
(slot windows-status
(allowed-strings "open" "close")))
CLIPS>
(defmessage-handler ROOM put-id before (?value)
(printout t "put-id event " ?self:id crlf))
CLIPS>
(defmessage-handler ROOM put-windows-status before (?value)
(printout t "put-window-status event " ?self:windows-status crlf))
CLIPS> (make-instance [r1] of ROOM (id room1) (windows-status "open"))
put-id event nil
put-window-status event nil
[r1]
CLIPS> (send [r1] put-id room2)
put-id event room1
room2
CLIPS> (send [r1] put-windows-status "close")
put-window-status event open
"close"
CLIPS>