The following is an adaptation of the draw.clp example. It
tries to embed the techniques of draw.clp within an inference
pattern-matching regime.
Everything is Ok up to a point, then it fails. Why? How can
it be fixed? All of the facts for rule listen-for-push are asserted,
but it does not fire. Why? Transcript under Win95 follows:
Jess> (batch draw2.clp)
FIRE [Defrule: start-it-all 1 patterns; salience: 0] f-0
<== (initial-fact)
==> Activation: continue-inference : f-1
==> (sample-fact)
FIRE [Defrule: continue-inference 1 patterns; salience: 0] f-1
<== (sample-fact)
I fired!
TRUE
Jess> Function pushed called
==> Activation: listen-for-push : f-2
==> (button-pushed)
It seems as if some implicit mainLoop is capturing the Jess
thread. If so, then --
- How to start a second engine?
- How to insert within its space, rather than in the
space of the GUI engine?
.clp file follows
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;
;; Draw2.clp
;; Simple example of using the jess.reflect classes to draw in a
;; Jess GUI without writing any Java code!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(clear)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utility routine invoked by jess.reflect.ActionListener.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deffunction pushed (?event)
(assert (button-pushed)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; closer(java.awt.event.WindowEvent)
;; Your generic window-closing event handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deffunction closer (?event)
(if (= (call ?event getID) (get-member ?event WINDOW_CLOSING))
then
(call (get ?event source) dispose)
;;;(call java.lang.System exit 0)))
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Create some components.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deffunction create-components ()
(assert (sample-fact))
(bind ?f (new java.awt.Frame "Drawing Demo"))
(?f addWindowListener (new jess.reflect.WindowListener closer (engine)))
(bind ?c (new java.awt.Button "Push Me"))
(?c addActionListener (new jess.reflect.ActionListener pushed (engine)))
(?f add "Center" ?c)
(?c setSize 100 100)
(?f pack)
(?f show))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Put things together and display
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule start-it-all
?f1<-(initial-fact)
=>
(retract ?f1)
(create-components)
)
(defrule continue-inference
?f1<-(sample-fact)
=>
(retract ?f1)
(printout t "I fired!" crlf)
)
(defrule listen-for-push
(button-pushed)
=>
(printout t "Button was pushed!" crlf)
)
(reset)
(watch all)
(unwatch compilations)
(run)
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------