I think Alexander Lamb wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> 
> However, I now need to do some more complex matching. Imagine I have a User
> object in my session and what to do something like:
> 
> (defrule startupRule1
>     (Session
>         (readyToRun TRUE)
>         (currentStateName "START")
>         (user (name "Alex"))
>         (OBJECT ?x)
>     )
>     =>
>     (call ?x setAdminMode)
> 
> The user object is an attribute of my session. The user class has been
> defined. But loading the rule, Jess tells me "bad slot value" (user is a
> watched attribute and name is an attribute of user). I would really like to
> avoid writing "cover methods" for every object contained in my session
> object.


You have to explicitly access the "property of the property", like this:

     (Session (readyToRun TRUE)
              (currentStateName "START")
              (user ?user&:(eq "Alex" (get ?user name)))
              (OBJECT ?x))
> 
> Later on, I would also like to test against multislot in the sense of having
> an ArrayList in my session object and do matching such as "if at least one
> of the object in the list is xyz then do something" or "find the first
> object in the list with xyz and take its value to compute something".

This isn't supported directly now, but again, you can achieve what you
want using explicit method calls. Here ?list is known to be an
ArrayList object:

      (someslot ?list&:(?list contains "xyz"))

If you want to bind a value from the contents of the list to a
variable on the LHS, then unfortunately, you simply can't, at least
not right now. What you have to do is move the test to the RHS of the
rule. In the rule below, there's no way to bind ?x on the LHS of the
rule, so we do it on the RHS:

(defrule foo
        ,..
        (someslot ?list)
        =>
        (bind ?x (find-special-value-in-list-somehow ?list))
        (if (neq ?x nil) then
           (so-something-with ?x)))

Note, though, that if a property is of an *array* type, then it gets
mapped onto a multislot, so you could use regular matching on the LHS.




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