Hi Julian,
I found out why your second example does not work. It is a result of
the statement in JiA p. 124
"If you don't specify a module, all deffacts, templates, and rules you
define automatically become part of the current module."
So, when you run your stuff in the following order:
Whereas the following does not:
(defmodule MODULE1)
(defrule rule1
(fact1)
=>
(assert (fact2)))
(assert (MAIN::fact1))
(focus MODULE1)
(run)
Your fact1 gets it 'first mentioning' (i.e. its definition) when the
current module is MODULE1. Pretty-printing your rule looks as follows:
(defrule MODULE1::rule1
(MODULE1::fact1)
=>
(assert (MODULE1::fact2)))
So, your rule puts fact1 in MODULE1, and therefore asserting
(assert (MAIN::fact1))
won't match and fire the rule.
You correctly figured out that either defining the deftemplate in MAIN,
or explicitly mentioning (MAIN::fact1) in the RHS of the rule makes
sure that fact1 actually ends up in module MAIN.
It helps to mention the module name to make sure that rules and facts
are actually in the module you expect.
HTH
Dona
On Jun 17, 2006, at 3:46 AM, Julian Hoch wrote:
Hi,
I have a little problem with firing rules in different modules
accessing facts in MAIN.
For example, the following works as expected:
(assert (fact1))
(defmodule MODULE1)
(defrule rule1
(fact1)
=>
(assert (fact2)))
(focus MODULE1)
(run)
Whereas the following does not:
(defmodule MODULE1)
(defrule rule1
(fact1)
=>
(assert (fact2)))
(assert (MAIN::fact1))
(focus MODULE1)
(run)
It seems like inserting the fact AFTER defining the rule does not work
here.
You have to define the template before defining the fact to make it
work again:
(deftemplate fact1)
(defmodule MODULE1)
(defrule rule1
(fact1)
=>
(assert (fact2)))
(assert (MAIN::fact1))
(focus MODULE1)
(run)
But, on the other side, the following works again:
(defmodule MODULE1)
(defrule rule1
(MAIN::fact1)
=>
(assert (fact2)))
(assert (MAIN::fact1))
(focus MODULE1)
(run)
This looks kind of wrong to me, since the rule should always look for
the facts in MAIN if not found in
the focus model. Can you explain this behaviour to me? I could not
find an explanation in the manual.
Thank you, Julian Hoch
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify
[EMAIL PROTECTED]
--------------------------------------------------------------------
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------