Re: JESS: CE can't be bound to a variable

"Ernest Friedman-Hill" <[email protected]>
Newsgroups gmane.comp.java.jess
Message-ID <[email protected]>
Your and/or version is actually not equivalent to the &&/|| version.  
"and" and "or", when nested outside of patterns, match separate facts  
-- i.e.,

(and (f (s 1) (f (s 2))

means "a fact 'f' with 1 in the slot 's', and another fact 'f' with 2  
in the slot 's'." Your "or" can't be bound to a variable because each  
branch contains two patterns and so will match two facts (although the  
two might actually not be distinct -- i.e., it could still match the  
same fact twice.)

There are also predicate functions named "and" and "or" which are  
distinct from these conditional elements of the same names. They are  
what you want to use, perhaps in a test CE for clarity:

(contactInfo (street ?s) (pob ?p))
(test (or (and (eq ?s "") (eq ?p "")) (and (neq ?s "") (neq ?p ""))))


On Sep 12, 2010, at 1:33 AM, Donald Winston wrote:

> I got the following rule to work:
>
> (defrule validate-contactInfo-street "validate contactInfo's street"
> 	?fact <- (contactInfo {street == "" && pob == "" || street != "" &&  
> pob != ""})		 	
> =>
> 	(modify ?fact (streetError "street xor po box is required")))
>
>
> But I can't get the "old style" version of this to work. I don't  
> know why.
>
> (defrule validate2-contactInfo-street "validate contactInfo's street"
> 	?fact <- (or (and (contactInfo (street ""))
>                                     (contactInfo (pob "")))
>                            (and (contactInfo (street ~""))
>                                     (contactInfo (pob ~""))))	 	
> =>
> 	(modify ?fact (streetError "street xor po box is required")))
>
> It says CE can't be bound to a variable. The ((( )))) look ok to me.

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
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].
--------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.