Hi Chris,

I'm actually rather happy with how this works -- let me try to clarify 
what's happening for you.

"DeGreef, Chris J. (AIT)" wrote:
> 
> (deffact somefacts
>         (head1 abc))
> is asserted as (MAIN::head1 abc)
> 
> (defmodule SUB)
> (deffact SUB::somemorefacts
>         (head1 def))
> is also asserted as (MAIN::head1 def)
> 
> Shouldn't the latter be asserted as (SUB::head1 def)?

The behaviour actually depends on whether or not MAIN::head1 or
SUB::head1 were previously defined. If the template MAIN::head1 exists, but
SUB::head1 does not, then the fact is created in MAIN, as you observe. But if
SUB::head1 already exists, or if neither SUB::head1 nor MAIN::head1 exists,
then the fact is a SUB::head1 fact.

> In fact, it only gets asserted in the module only when specified like
> (deffact SUB::somemorefacts
>         (SUB::head1 def))

As stated above, this isn't quite true.

> 
> More specifically, any facts in the deffact statement, defined before a fact
> definition referencing a module, are asserted to the MAIN:: module.  All
> facts after a specific module fact are asserted to that same specific
> module.

Again, that's not quite it; the facts end up in MAIN -only- if the necessary template
already exists in the MAIN module.

> 
> Effectively, all deffacts, regardless of the defmodule they follow, by
> default extend the MAIN:: repository of facts and are accessable to all
> modules.  This is unlike the assert statement, when executed in a module,
> which asserts the fact with the <module>:: prefix on the fact as a default.
> 

No, (assert) follows exactly the same rules -- the same code is used to do
the template lookup.


> I have a related question about modules and the scope of facts.
> 
> If the same fact head is defined in both modules, like ...
> 
>         (deffact MAIN::somefacts
>                 (head1 abc)
>         ...
>         (deffact SUB::someotherfacts
>                 (SUB::head1 def)
> 
> then a rule in module SUB will not fire with the (head1 abc) fact.  As in...
> 
>         (defrule SUB:rule1
>                 (head1 ?a)
>                 =>
>                 (printout t ?a crlf))
> 
> This only prints "def".
> 
> Shouldn't the facts defined as MAIN:: be accessable to all modules even when
> the names of the facts are the same?
> 

MAIN::head1 and SUB::head1 are two different templates -- patterns can only
match one or the other. Which one they match is decided when the rule is compiled.
The first pp of mainual section 2.10.2 is pretty clear about this.



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

---------------------------------------------------------------------
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]
---------------------------------------------------------------------

Reply via email to