I think qfhe wrote:
> 
> Now my question is how I'm going to use those objects
> in rule specification. Suppose I added two instance of
> the same type Customer to the working memory. I want
> to define a rule to check whether the two customers
> have the same name. "name" is a private field in class
> Customer and I provide setter and getter methods in
> the class to access this field. Could you please give
> me some sample code to do this. Thanks very much.
> 

You wouldn't say this as "if the two customers have different names",
but rather "if there's a customer with name ?n and a different
customer whose name is also ?n". This way the same rule works no
matter how many customers there are. One way to write this:

(defrule two-customers-same-name
    ;; Read this as "There's a Customer object ?o1 with name ?n"
    (Customer (OBJECT ?o1) (name ?n))

    ;; Read this as "There's another Customer ?o2 which is not ?o1,
    ;; and whose name is also ?n
    (Customer (OBJECT ?o2&~?o1) (name ?n))
    => 
    ;; Here the variables ?o1 and ?o2 refer to the two Customer
    ;; objects, and ?n1 is their shared name; you can take
    ;; whatever action you like. 


> p.s. The following example on the same page of the
> documentation seems require some other things to work.
> Is the source for this example available?
> 
> (defrule 10%-volume-discount
>     "Give a 10% discount to everybody who spends more
> than $100."
>     (Order {total > 100})
>     =>
>     (add (new Offer "10% volume discount" (/ ?total 10))))
> 


It would require a class named "Order" with a bean property "total",
and class "Offer" with a constructor that took a String and a number
as constructor arguments. The example should be complete in the final
release; note that Jess 7 is still in beta.




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