I think Alan Littleford wrote:
> Ernest,
>
> thanks for the response. I had thought of using executeCommand but reasoned that
> it was actually more expensive than my rule because each time it is executed (which
> may be quite a number of times) I pay the penalty of having to parse and compile the
> command. Just of of curiosity (and because I'm too lazy to check it out) do you have
> a feel for which would win in terms of speed -- compiling the string each time or
> executing the rule ??
>
Neither is going to be particularly expensive. I think you're right to
avoid executeCommand() when performance is an issue.
> Anyway your second approach definitely rules (arghh) and I should have thought of it.
> Generally speaking would it be useful to bring definstace out as a Rete method (or
> however your new factoring is going to look)? I can assert from within rete --
> wouldn't it seem that definstance shares the same position in the scheme of things
> (especially as I find one of the joys of Jess to be the Bean<->(shadow)Fact duality)
> ?
>
You have a good point about adding a definstance() method in Rete (or
Shell, or Jess, or whatever the class will be called.) I will remember
that.
> Tnx
> Alanl
>
>
> [EMAIL PROTECTED] wrote:
>
> > You're right that there's no direct method you can call to create a
> > definstance from Java, although the same is true of many other Jess
> > functions. Instead you can either do something like what you've done
> > below, or create and use a Funcall object.
> >
> > First, an improvement on the scheme below that doesn't require a rule!
> >
> > rete.store("FOO", obj);
> > rete.executeCommand("(definstance class-name (fetch FOO) dynamic)");
> >
> > Second, the Funcall approach. First, build the funcall:
> >
> > Funcall f = new Funcall("definstance", rete);
> > f.add(new Value("class-name", RU.ATOM));
> > f.add(new Value(obj));
> > f.add(new Value("dynamic", RU.ATOM));
> >
> > Then you can execute it once:
> >
> > f.execute(rete.getGlobalContext());
> >
> > Then you can reuse it as many times as necessary:
> >
> > f.set(newObj, 2); // replace obj with newObj
> > f.execute(rete.getGlobalContext());
> >
> > Wrap these last two lines in a method called definstance(Object)
> > someplace, make f a member of the method's class,and you're all set.
> >
> > I think Alan Littleford wrote:
> > > Forgive me if I've missed something obvious but:
> > >
> > > I cannot see a way of 'Definstancing' from within a Userfunction --
> > > the Definstance functionality within Jess seems private. Is this by
> > > design, or am I just mssing something very obvious? As it is now I
> > > simply assert a fact 'foo(OBJECT ?obj)' from my user function ( where
> > > ?obj is the address of my Bean created within my user function) and then
> > > I have a rule within Jess along the lines of :
> > >
> > > (defrule defitup
> > > ?f<-(foo (OBJECT ?obj))
> > > =>
> > > (definstance <?class-name> ?obj dynamic)
> > > (retract ?f) ;; don't need it any more
> > > )
> > >
> > > which although it works fine seems to be laborious at best. BTW I'm
> > > using Jess 5.1 (still intending to move to Jess 6 at some point!)
> > >
> > > Thanks to anyone who can shed light on this
> > >
> > > Alanl
> > >
> > > ---------------------------------------------------------------------
> > > 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]
> > ---------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------