Hi,
What you're doing here should work (in fact, I just checked it in
5.0a2 just to see if it would work as expected, and it does.) I
suspect that your problems are probably due to typographical errors -
in the first example, perhaps find-os doesn't even fire to due a typo,
hence the NullPointerException (when you try to call stringValue on
the null return value of fetch(), since nothing was ever stored) and
in the second example, you may have either left the '?' off of osname
in the 'store' statement, or misspelled osname earlier in the rule, so
that what gets stored in the name of an undefined variable (Jess won't
report an error in this case, alas; it will simply use the variable's
name.) I notice in the examples below that both rules are missing
terminating parentheses.
I think Kyung Koo Jun wrote:
>
>
> Thank you for your answer,, but I found funny things.
>
> First I tried,
>
> (defrule find-os
> ?ask-stmt <- (ask-os ?hostname)
> (has-os ?hostname ?osname)
> =>
> (retract ?ask-stmt)
> (store OSNAME ?osname)
> (assert (has-os myhost unix))
>
> Rete rete = ...
> rete.executeCommand("(assert (ask-os myhost))");
> rete.run();
> System.out.println("OS is "+rete.fetch("OSNAME").stringValue());
>
> The result is NullPointerException.
> The return value of rete.fetch("OSNAME") is null
>
> Next I modifed find-os rule,
> inserting (printout t ?hostname......)
>
> (defrule find-os
> ?ask-stmt <- (ask-os ?hostname)
> (has-os ?hostname ?osname)
> =>
> (retract ?ask-stmt)
> (printout t ?hostname" has "?osname crlf)
> (store OSNAME ?osname)
>
> The result is "OS is osname", not what I expected "OS is unix"
> The problem is that the variable ?osname is not dereferenced.
>
> Could you let me know where I did make mistakes?
> I'm using "jess50a2".
>
> Thanks in advance.
>
> On Wed, 13 Jan 1999, Ernest Friedman-Hill wrote:
>
> > There are many ways. One easy one is to use the 'store' and 'fetch'
> > functions.
> >
> > (defrule find-os
> > ?ask-stmt <- (ask-os ?hostname)
> > (has-os ?hostname ?osname)
> > =>
> > (retract ?ask-stmt)
> > (store OSNAME ?osname)
> > (assert (host-os myhost unix))
> >
> >
> > Rete rete = ...
> > rete.executeCommand("(assert (ask-os myhost))");
> > rete.run();
> > String osname = rete.fetch("OSNAME").stringValue();
> >
> > See the README for details.
> >
> > I think Kyung Koo Jun wrote:
> > >
> > >
> > > Hi, all,
> > >
> > > In my case, test.clp is
> > >
> > > (defrule find-os
> > > ?ask-stmt <- (ask-os ?hostname)
> > > (has-os ?hostname ?osname)
> > > =>
> > > (retract ?ask-stmt)
> > > (printout t ?osname crlf))
> > > (assert (host-os myhost unix))
> > >
> > > in Java application
> > >
> > > Rete rete = ...
> > > rete.executeCommand("(assert (ask-os myhost))");
> > > rete.run();
> > >
> > > then Jess will print the result "unix" into
> > > standard output.
> > > However I'd like to make the Java application get
> > > the result.
> > >
> > > Which way is the smartest one?
> > > Thanks in advance for the answers to the studpid question.
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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]
> > > ---------------------------------------------------------------------
> > >
> > >
> >
> >
> > ---------------------------------------------------------
> > Ernest Friedman-Hill
> > Distributed Systems Research Phone: (925) 294-2154
> > Sandia National Labs FAX: (925) 294-2234
> > Org. 8920, MS 9214 [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. 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. 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 9214 [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. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------