Ernest,

I've found two apparent problems mapping long values from Java to Jess.
Not only is it not seemless, but long values in shadow facts appear to be
incorrect,
causing rules that should fire to not fire.

I'm using Windows NT 4.0
JDK 1.2.2
Jess 50b2 and 50b3.


Problem 1: Some values for the "date" slot in the shadow fact for Thing
objects are incorrect.
All the same values for the deftemplate jessthing with the slot "date" work
correctly.
Rules 2, 7 and 14 (in date.clp) suggest that the decision to map a number as
an integer or a double is
based on the number of digits in the string form of the number--10-digit
numbers work correctly, 
11-plus-digit numbers do not--but that is speculation only, I haven't looked
at the code.
(Java's MAXINT currently has 10 digits in it...)        

Problem 2: If the object instances are created from Jess, as opposed to from
Java, Jess will expect
a Java constructor that takes a double instead of a long, for 11-plus-digit
numbers, crashing 
if such a constructor doesn't exist. This seems to me to be more than just
an inconvenience.

Note: My code indicates that *I'm* thinking of these values as dates, but
that's incidental.

Here are the files and the results:

;;;;;;;;;;;;;; begin date.clp test file ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; jessthing is a "copy" of thing, but is a template instead of a Java class
;;
(defclass thing Thing)
(deftemplate jessthing (slot date))


;; 2147483647 is the current value of Java's max integer.
(defrule Rule1
        (thing (date 2147483647))
        =>
)

;; -2147483647 is the current value of Java's min integer.
(defrule Rule2
        (thing (date -2147483647))
        =>

)

;;  2100000000 is in-between Java's max and min.
(defrule Rule3
        (thing (date 2100000000))
        =>

)

; this number is a long (not an integer)
(defrule Rule4
        (thing (date  -60067621520002))
        =>

)

; this number is the additive inverse of the one in rule 4
(defrule Rule5
        (thing (date 60067621520002))
        =>

)

;; -2147483648 is one less than Java's min integer (i.e. MIN -1).
(defrule Rule6
        (thing (date  -2147483648))
        =>

)

;; -21474836479 has one more digit than Java's min integer (it's a long)
;; this number is to test a theory that the boundary between values that
work properly
;; and values that don't is the number of digits in the number string.
(defrule Rule7
        (thing (date -21474836489))
        =>

)

;;
;;jessthing copies  of rules 1-7
;; These rules illustrate that using deftemplates appears
;; to work correctly in cases where mapping from an "identical" Java
;; object fails.
;;
(defrule Rule8
        (jessthing (date 2147483647))
        =>

)


(defrule Rule9
        (jessthing (date -2147483647))
        =>

)


(defrule Rule10
        (jessthing (date 2100000000))
        =>

)

(defrule Rule11
        (jessthing (date  -60067621520002))
        =>

)

(defrule Rule12
        (jessthing (date 60067621520002))
        =>

)

(defrule Rule13
        (jessthing (date  -2147483648))
        =>

)

(defrule Rule14
        (jessthing (date -21474836489))
        =>

)

(defrule startup_rule
  =>
  (watch all)
  (definstance thing (bind ?thing1 (new Thing 2147483647)))
  (definstance thing (bind ?thing2 (new Thing -2147483647)))
  (definstance thing (bind ?thing3 (new Thing 2100000000)))
  (definstance thing (bind ?thing4 (new Thing -60067621520002)))
  (definstance thing (bind ?thing5 (new Thing 60067621520002)))
  (definstance thing (bind ?thing6 (new Thing -2147483648)))
  (definstance thing (bind ?thing7 (new Thing -21474836489)))
  
  (assert (jessthing (date 2147483647)))
  (assert (jessthing (date  -2147483647)))
  (assert (jessthing (date 2100000000)))
  (assert (jessthing (date -60067621520002)))
  (assert (jessthing (date 60067621520002)))
  (assert (jessthing (date -2147483648)))
  (assert (jessthing (date -21474836489)))
  
  )

(reset)
(run)

;;;;;;;;;; end of date.clp test file ;;;;;;;;;;;;;;;;

/******************** begin Thing.java test object **************/
import java.beans.*;
import java.util.*;
import java.text.*;
/**
 * Thing.java
 *
 *
 * Created: Tue Nov 23 16:41:22 1999
 *
 * @author George Rudolph
 * @version
 */

public class Thing  {
        
        private long m_date;

        public Thing(long date) {
                System.out.println("used constructor with primitive long
value: " + date);
                Date d = new Date(date);
                System.out.println("This value corresponds to date: " +
DateFormat.getDateInstance().format(d));
                m_date = date;
        }

        //no pun intended... ;)
        /**
         * I had to include this constructor not because I wanted to, but
because the definstances 
         * for thing4, thing5 and thing7 [see the file date.clp startup
rule] crash without it.
         * This means the user of Jess has to know which values are
converted to doubles, and
         * provide some appropriate conversion mechanism (not necessarily a
constructor, which
         * is at least ugly, and in some cases impossible.)
         */
        public Thing(double date) {
        System.out.println("used constructor with primitive double value: "
+ date);
                Double d1 = new Double(date);
                long value = d1.longValue();
                Date d = new Date(value);
                System.out.println("This value corresponds to date: " +
DateFormat.getDateInstance().format(d));
                m_date = value;
        }
        public void setDate(long date) {

                if (date != m_date) {
                        long   tmp = m_date;
                        m_date = date;
                        
                        pcs.firePropertyChange("date", new Long(tmp),
        
new Long(date));
                }
        }

        public long getDate() {
                return m_date;
        }

  private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  public void addPropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.addPropertyChangeListener(pcl);
  }
  public void removePropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.removePropertyChangeListener(pcl);
  }
} // Thing

/*********************** end Thing.java
************************************/


Results of running 
        java jess.Main date.clp



Jess, the Java Expert System Shell
Copyright (C) 1998 E.J. Friedman Hill and the Sandia Corporation
Jess Version 5.0b3 11/30/99

used constructor with primitive long value: 2147483647
This value corresponds to date: Jan 25, 1970
 ==> f-1 (thing (class <External-Address:java.lang.Class>) (date 2147483647)
(OBJECT <External-Address:Thing>))
==> Activation: Rule1 :  f-1
used constructor with primitive long value: -2147483647
This value corresponds to date: Dec 6, 1969
 ==> f-2 (thing (class <External-Address:java.lang.Class>) (date
-2147483647) (OBJECT <External-Address:Thing>))
==> Activation: Rule2 :  f-2
used constructor with primitive long value: 2100000000
This value corresponds to date: Jan 25, 1970
 ==> f-3 (thing (class <External-Address:java.lang.Class>) (date 2100000000)
(OBJECT <External-Address:Thing>))
==> Activation: Rule3 :  f-3
used constructor with primitive double value: -6.0067621520002E13
This value corresponds to date: Jul 15, 0066
 ==> f-4 (thing (class <External-Address:java.lang.Class>) (date 1791081854)
(OBJECT <External-Address:Thing>))
used constructor with primitive double value: 6.0067621520002E13
This value corresponds to date: Jun 19, 3873
 ==> f-5 (thing (class <External-Address:java.lang.Class>) (date
-1791081854) (OBJECT <External-Address:Thing>))
used constructor with primitive long value: -2147483648
This value corresponds to date: Dec 6, 1969
 ==> f-6 (thing (class <External-Address:java.lang.Class>) (date
-2147483648) (OBJECT <External-Address:Thing>))
==> Activation: Rule6 :  f-6
used constructor with primitive double value: -2.1474836489E10
This value corresponds to date: Apr 27, 1969
 ==> f-7 (thing (class <External-Address:java.lang.Class>) (date -9) (OBJECT
<External-Address:Thing>))
 ==> f-8 (jessthing (date 2147483647))
==> Activation: Rule8 :  f-8
 ==> f-9 (jessthing (date -2147483647))
==> Activation: Rule9 :  f-9
 ==> f-10 (jessthing (date 2100000000))
==> Activation: Rule10 :  f-10
 ==> f-11 (jessthing (date -6.0067621520002E13))
==> Activation: Rule11 :  f-11
 ==> f-12 (jessthing (date 6.0067621520002E13))
==> Activation: Rule12 :  f-12
 ==> f-13 (jessthing (date -2147483648))
==> Activation: Rule13 :  f-13
 ==> f-14 (jessthing (date -2.1474836489E10))
==> Activation: Rule14 :  f-14
FIRE 2 Rule14 f-14
FIRE 3 Rule13 f-13
FIRE 4 Rule12 f-12
FIRE 5 Rule11 f-11
FIRE 6 Rule10 f-10
FIRE 7 Rule9 f-9
FIRE 8 Rule8 f-8
FIRE 9 Rule6 f-6
FIRE 10 Rule3 f-3
FIRE 11 Rule2 f-2
FIRE 12 Rule1 f-1

/************* end results ********************************/
---------------------------------------------------------------------
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