Hi Matthias,

I can explain what's going on, but what I can't say for sure is
whether you should consider this a bug or a feature. What's happening
is that Jess is letting you see a glimpse of its internal operation,
which may or may not be right -- I haven't decided.

The essential point of the explanation is that the fact-id ?x returned
by (assert) is not really the exact same kind of fact you get out of
tokens returned by defqueries. The former kind are the "inputs" to the
Rete network, while the latter kind are the "outputs." Under some
circumstances the two are the same, but when multislots are involved,
they are not.

I'm going to make this short. Basically, the multislot (ids) in ?x
contains (a b c) -- three entries, each a single atom. The multislot
in the fact you get from the defquery contains ((a b c)) -- a one-item
list, the first item of which is the list (a b c). I won't explain why
this is other than to say that it has to do with how Jess matches the
contents of multislots to variables during pattern-matching; since
here you'e using one variable to match that slot, the slot you see
contains only one item, a list with all the slot values in it.

One simple way to get around this is to "resolve" the fact; look up
the "input" fact object that corresponds to the output fact
object. This is always safe to do, and works whether the input and
output are the same or different. So you might rewrite
xxdelete-child-from-relation-container like this:

 (deffunction resolve-fact (?FACT)
     (call (engine)  findFactByID (call ?FACT getFactId)))

 (deffunction xxdelete-child-from-relation-container (?FACT ?Y)
     (bind ?FACT (resolve-fact ?FACT))
     (bind $?multiY (create$ ?Y))
     (bind ?rest (fact-slot-value ?FACT ids))
     (bind ?new-ids (complement$ $?multiY ?rest))
     (printout t "new-ids" ?new-ids))
                               

I think Matthias Blankenhaus wrote:
> Hi !
> 
> I am trying to change a fact in a mutlislot field and cannot get it to
> work. Here is the relevant code:
> 
> (deftemplate contains (slot containerId) (multislot ids))
> 
> (defquery find-container
>     (declare (variables ?X))
>     (contains (containerId ?X) (ids $?Y)))
> 
> (deffunction xxdelete-child-from-relation-container (?FACT ?Y)
>                     (bind $?multiY (create$ ?Y))
>                     (bind ?rest (fact-slot-value ?FACT ids))
>                     (bind ?new-ids (complement$ $?multiY ?rest))
>                     (printout t "new-ids" ?new-ids))
> 
> (deffunction  yydelete-child-from-relation-container (?X ?Y)
>     (bind ?obj (run-query find-container ?X))
>     (bind ?tmp (call ?obj next))
>     (bind ?container-obj (call ?tmp fact 1))
>         (xxdelete-child-from-relation-container ?container-obj ?Y))
> 
> (bind ?x (assert (contains (containerId 1) (ids a b c))))
> 
> Now, if I call (xxdelete-child-from-relation-container ?x c) then it 
> works !  Here I pass in directly a fact.
> 
> If I do (yydelete-child-from-relation-container 1 c), thereby using the
> defquery, it does not work, althought ?container-obj represents the same
> fact as ?x.
> 
> What's the problem ?
> 
> thanx,
> 
> Matthias
> 
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------

Reply via email to