I think Vincent Wolowski wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Thanks a lot for the reply.
> I want to compare strings. 
> If I look at the result of the printout-function, there are a few facts in my 
>knowledge base, where the variables have the same value. 
> I tried eq, eq* and str-compare. 
> Only str-compare worked. I dont understand, why eq doesnt work. 

My previous explanation concentrated on the difference between
INTEGER, FLOAT, and STRING, but I still believe it is probably
correct. Even all of your quantities are string-like, and not numeric,
don't forget there are two string-like types in Jess: STRING
(double-quoted string literals) and ATOM (unquoted symbols.) (eq) and
(eq*) will return FALSE if they are comparing a STRING to an ATOM,
even if both appear to have the same value -- i.e., (eq "FOO" FOO) and
(eq* "FOO" FOO) are both FALSE. (str-compare "FOO" FOO) will return 0,
indicating that they're equal. Again, the point is that eq and eq* are
deliberately, by definition, very picky about the comparison they do,
and if you don't understand why, it's safe to simply never use
them. In general, using = for numeric comparison and str-compare for
string comparison is a perfectly reasonable thing to do.
 
> It uses the Java Object.equals() function, and you can compare strings with it. I 
>found in the mailing-archiv the question, what the difference would be of eq* and 
>str-compare. The answer there was:
> I think (test (eq* ?X "ABC")) may be fast because, (test (= 0 (str-compare
> ?X "ABC"))) requires one extra operation.
> I guess I miss something.

No, you didn't miss anything; you just had some bad information. I
searched the mailing list archive and found the post you're referring
to (at
http://www.mail-archive.com/[email protected]/msg03118.html) . The
poster was simply wrong. eq* and str-compare do different things.  eq*
compares types and returns false if they're not the same, while
str-compare tries to convert everything to a STRING.

If (= 0 (str-compare "FOO" FOO)) is too verbose, you can easily define
a "str-equals" function:

(deffunction str-equals (?s1 ?s2)
  (return (= 0 (str-compare ?s1 ?s2))))        

and then call that instead.

> Thanks for any help.
> 
> Vincent
> 
> defrule match-price-and-quality
>     (Tag (TagName "price") (Text ?u))
>     (Tag (TagName "quality") (Text ?t))
>     (servicequality ?quality) 
>     (serviceprice ?price) 
>     ;;(test (eq ?quality ?t))
>     ;;(test (eq* ?quality ?t))
>     (test (= 0 (str-compare ?quality ?t)))
>     =>
>     (printout t "---- quality ------------- : " ?t crlf )
>     (printout t "---- servicequality ------ : " ?quality crlf )) 
> 
> 
> 
> 
> 
> [EMAIL PROTECTED] schrieb am 04.06.02:
> > (eq) is a very strong test; (eq 1 1.0) is FALSE, as are (eq 1 "1"),
> > (eq "1" 1.0), and all the permutations. Both the types and the values
> > of the variables must match. STRING, INTEGER, and FLOAT are all
> > different types. My guess is that ?quality and ?t have different
> > types.
> > 
> > The "=" function is much looser, and will convert types as needed:
> > (= 1 1.0), (= "1" 1.0), etc. are all TRUE. Try using "=" instead of
> > "eq". 
> > 
> > I think Vincent Wolowski wrote:
> > [Charset iso-8859-1 unsupported, filtering to ASCII...]
> > > I have the following rule:
> > > 
> > > (defrule match-price-and-quality
> > >     (Tag (TagName "price") (Text ?u))
> > >     (Tag (TagName "quality") (Text ?t))
> > >     (servicequality ?quality) 
> > >     (serviceprice ?price) 
> > >     (test (and (eq ?quality ?t) (<= ?u ?price)))
> > >     =>
> > >     (printout t "---- price ----------- : " ?u crlf )
> > >     (printout t "---- quality --------- : " ?t crlf )
> > >     (printout t "---- serviceprice ---- : " ?price crlf )
> > >     (printout t "---- servicequality -- : " ?quality crlf )) 
> > > 
> > > If I comment the test CE, the rule gets activated and fires.
> > > The values of the variables are OK.
> > > I have no idea, why it doesn_t work with the test CE.
> > > Thanks for any help!
> > > 
> > > Vincent



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