|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
JESS: Type precision causes duplicate factsHello, As part of testing the problem from my previous posting, I
noticed a strange duplication of facts when trying to create a fact with a slot
of FLOAT type. In one case I am specifying a decimal and the other a whole
number, but the number is otherwise the same. I would think only one fact
would be created, but instead two are created but with different float
representations. The values are equal according to the = operator;
however the eq operator returns false. Is this behavior to be expected and intended by design? I
would think the slot with type Float would automatically convert all raw values
to float and so only create one fact in the example below. (deftemplate x "blah" (slot
num (type FLOAT))) (defrule dupFact ?x1 <- (x (num ?num1)) ?x2 <- (x (num ?num2&:(and
(<> ?x1 ?x2) (= ?num1 ?num2)))) => (printout
t "dup facts with values " ?num1 " " ?num2 crlf) ) (reset) (assert (x (num 1157650583.0))) (assert (x (num 1157650583))) (run) (facts) ---- Jess, the Rule Engine for the Java Platform Copyright (C) 2008 Sandia Corporation Jess Version 7.1p2 11/5/2008 MAIN::dupFact: +1+1+2+t ==> Focus ==> f-0 (MAIN::initial-fact) ==> f-1 (MAIN::x (num
1.157650583E9)) ==> f-2 (MAIN::x (num
1157650583)) ==> Activation: MAIN::dupFact : f-2, f-1 ==> Activation: MAIN::dupFact : f-1, f-2 FIRE 1 MAIN::dupFact f-1, f-2 dup facts with values 1.157650583E9 1157650583 FIRE 2 MAIN::dupFact f-2, f-1 dup facts with values 1157650583 1.157650583E9 <== Focus MAIN f-0 (MAIN::initial-fact) f-1 (MAIN::x (num 1.157650583E9)) f-2 (MAIN::x (num 1157650583)) For a total of 3 facts in module Thanks, Brian |
|
|
Re: JESS: Type precision causes duplicate factsOn Jun 8, 2009, at 9:18 PM, Brian Rogosky wrote: > Hello, > As part of testing the problem from my previous posting, I noticed a > strange duplication of facts when trying to create a fact with a > slot of FLOAT type. In one case I am specifying a decimal and the > other a whole number, but the number is otherwise the same. I would > think only one fact would be created, but instead two are created > but with different float representations. The values are equal > according to the = operator; however the eq operator returns false. The whole number is an RU.INTEGER, and the float is an RU.FLOAT. Comparing with = returns true because they have the same value, but eq returns false because they're different data types. Variables and slots are untyped in Jess; only values have types. The "type" slot qualifier is included only for backwards compatibility with CLIPS; in Jess, as in CLIPS, it doesn't actually prevent a value of another type from being added to the slot. It's more for documentation than anything else. It's definitely not like a variable declaration in Java. > > Is this behavior to be expected and intended by design? Yes. > I would think the slot with type Float would automatically convert > all raw values to float and so only create one fact in the example > below. Nope. 1 and 1.0 are two different values. When it matters, use "=" for comparison. --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012 ejfried@... Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
| Free embeddable forum powered by Nabble | Forum Help |