Thanks. It runs perfectly now.  Of course, run-query* is a wonderful
solution for the jess user.
I understand that "initial-facts" was used in a lot of place, JIA mentioned
not or test conditional check.
Referring to the example from JIA section 7.7:  affordable.clp
that run-query use fact "1" without that initial-facts inserted. Is that
because the query is neither backward chaining nor not/test match, so Jess
don't need to insert the initial-facts?


Backward chaining doesn't support function calls inside. Are will going to
see the support in the near future?
Thanks,
Jade Fang

On 5/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

The initial-fact pattern is inserted into the query just as it would
be inserted into any rule that starts with a
backward-chaining-reactive pattern. If you use run-query*, it knows
that, and does the right thing. To use the old run-query, you'd have
to understand that yourself and allow for it -- here, by using "2" for
the fact index instead of "1". It's terrible to expect people to think
about this kind of thing, which is why run-query* was invented.

The old-style run-query will be supported for Jess 7, but may be
removed by Jess 7.1.


Finally, to get at the fact objects in a query using run-query*, you
just bind them to variables as you would in a normal rule:

(defquery foo
  ?x <- (foo))

Then you can ask the QueryResult for ?x and retract it.

I think jade fang wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> I was playing with backward chaining, and use fib as examples:
> The following scripts use run-query*, and use resultset to get the value
> without any problem:
>
> (watch all)
> (deftemplate fib
>     (slot sequence)
>     (slot value))
>
> (do-backward-chaining fib)
>
> (defrule recurse
>     ?need <- (need-fib (sequence ?n))
>     =>
>     (assert (fib (sequence ?n) (value (call (get-fib-value (- ?n 1)) add
> (get-fib-value (- ?n 2))))))
>     (retract ?need)
> )
>
> (defquery fetch-fibs
>     (declare (max-background-rules 10) (variables ?s))
>     (fib (sequence ?s) (value ?v))
> )
>
> (deffacts initial-fibs
>     (fib (sequence 1) (value (get-member java.math.BigInteger ONE)))
>     (fib (sequence 2) (value (get-member java.math.BigInteger ONE))))
>
> (deffunction get-fib-value(?sequence)
>     (if (> ?sequence 0)
>     then
>         (bind ?list (run-query* fetch-fibs ?sequence))
>         (while (?list next)
>             (return (?list getObject v))
>         )
>     )
>     (return 0)
> )
>
> While I change get-fib-value use run-query function:
> (deffunction get-fib-value(?sequence)
>     (if (> ?sequence 0)
>     then
>         (bind ?list (run-query fetch-fibs ?sequence))
>         (foreach ?token ?list
>             (return (fact-slot-value (call ?token fact 1) value))
>         )
>     )
>     (return 0)
> )
> Everything else remains the same,  but I got the error message:
> Jess reported an error in routine Fact.findSlot
>         while executing (fact-slot-value (call ?token fact 1) value)
> .....
>   Message: No slot value in deftemplate  MAIN::initial-fact.
>
> I can't find any error in my clp files. I will need some help to explain
why
> I get different result using run-query and run-query*.
>
> Also, no matter how I wrote the clp file, the initial-fact should not
> returned as query result, right?
>
> I'm using jess 7.0b6, and noticed that online doc talks about the
run-query
> has been depreciated.
> Does that mean the run-query won't be supported as expected?
>
>
> Also I have another question: run-query*'s resultset seems very easy for
> data manipulation.
> But it's no longer a fact object anymore. How can I get hold of the fact
> from its resultset so that I can use retract function?
>
> Thanks for the help.
> Regards,
>  Jade Fang



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

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