First of all, this is a very nice use of the "advice" facility -- the
kind of thing for which it is intended. I hadn't heard of anyone else
using it so far, so I'm happy to see you getting some mileage from it.
Second, I think that Jess's current behaviour in this circumstance is
kind of odd; modify changes the real object, but the shadow fact is
not altered. If anything, it should be the other way around. Ideally,
it should do what you've accomplished here. You can assume that a
future version of Jess 6 will behave the way you'd expect.
Hmmm. Since fact-ids aren't going to change from now on, and therefore
since therefore a single jess.Fact object represents a fact the whole
time it exists, I could do the object-oriented thing and produce a few
subclasses of Fact, RegularFact, DynamicShadowFact and
StaticShadowFact. The complicated code for (modify) could be reduced
to a single call Fact.modify(args), and the code could be distributed
among the various children. This would make this easy without
requiring the extra data member for "isBound()".
This could get rid of some of the ugly tables and lookups in
ReflectFunctions as well. I like the way that sounds.
I think Richard Long wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> I'm currently in a situation that may not be unique.
> I have a complex set of precompiled classes which I need to incorporate into
> the
> knowledge base. They are standard beans and Jess casts them as shadow facts
> just fine. However, they are not Bound beans, and so I have the obvious
> problem that Jess shadow facts are not updated when using the modify
> function. Since I have no control over these classes directly, and I want
> to save myself the overhead of adding anything like a set of wrapper
> classes, I've used defadvice to alter the behavior of the modify function so
> that objects are undefinstanced and redefinstanced following a modify.
>
> My question is, is this the most efficient way of handling this? One bad
> side effect is that the fact-id for static definstances is changed after a
> modify, breaking a wonderful new feature of Jess6.0. Are there any plans in
> the future to allow shadow facts to be updated for static definstances?
>
> The new modify function is as follows. It's assumed that an additional slot
> named "isBound" has been added to tell us which definstances are dynamic.
> This slot might be a good thing for definstance to add automatically in
> future releases of Jess. :-)
>
> (defadvice after modify
> (if (?retval isShadow)
> then
> (bind ?_id (?retval getFactId))
> (if (not (fact-slot-value ?_id isBound))
> then
> (bind ?_object (fact-slot-value (?retval getFactId) OBJECT))
> (undefinstance ?_object)
> (return (definstance (call (?retval getDeftemplate) getName)
> ?_object static))
> )
> )
> )
>
> By the way, I have a Jess function called 'make-facts' which takes an
> object, and recursively creates defclasses and definstances for that object
> and all of it's properties that are objects. In addition, if the object
> class extends another class, a defclass is created recursively for all
> parent classes with the defclasses appropriately extended.
>
> In other words, complex java objects are fully parsed into Jess
> automatically.
>
> I'll post the recurse.clp file here if anyone is interested.
>
> Richard Long
> Senior Consultant
> Breakaway Solutions, Inc.
> 20 North Orange Ave, 14th Floor
> Orlando, FL 32801
> http://www.breakaway.com
> GET THERE FIRST!
>
>
>
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
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]
---------------------------------------------------------------------