In attempting to use the new features involved with long types, I've run
into some problems as described below.
I put my questions here at the top (for convenience) because the description
is somewhat involved.

Question1: How do you tell the Jess parser that a number like
-60067621520002 is a long value, as opposed to a double or a string?
Question 2: Knowing that slot values in Jess are typeless, how do I specify
a rule pattern that will correctly match against NewThing objects?


Given a Java object NewThing, which has as one of its properties a long
value,
I'm having problems both creating and pattern matching against long values
in
ways that I would expect to be able to.  I did find one solution, but it
seems more complex
than it needs to be, so I think I'm forgetting something simple or missing
the boat on this.
The Java code and .clp file are given below. I'm using Sun JDK 1.2.2 and
Jess 50b4.


Problem 1:
-----------------

If I run the following .clp file,

;;begin file
        (defclass thing NewThing)

        (defrule startup_rule
        =>
        (definstance thing (bind ?thing1 (new NewThing -60067621520002)))
        )

        (reset)
        (run)

;; end file

I get the following exception,


Jess reported an error in routine new while executing (new NewThing
-6.0067621520002E13) while executing (bind ?thing4 (
new NewThing -6.0067621520002E13)) while executing (definstance thing (bind
?thing4 (new NewThing -6.0067621520002E13)))
 while executing defrule startup_rule while executing (run).
  Message: Constructor not found: (new NewThing -6.0067621520002E13).
  Program text: ( run )  at line 9.
Nested exception is:
NewThing
java.lang.NoSuchMethodException: NewThing
        at jess.JessNew.call(ReflectFunctions.java, Compiled Code)
        at jess.FunctionHolder.call(FunctionHolder.java:37)
        at jess.Funcall.execute(Funcall.java:240)
        at jess.FuncallValue.resolveValue(FuncallValue.java:33)
        at jess.Bind.call(Funcall.java:767)
        at jess.FunctionHolder.call(FunctionHolder.java:37)
        at jess.Funcall.execute(Funcall.java:240)
        at jess.FuncallValue.resolveValue(FuncallValue.java:33)
        at jess.Definstance.call(ReflectFunctions.java:882)
        at jess.FunctionHolder.call(FunctionHolder.java:37)
        at jess.Funcall.execute(Funcall.java:240)
        at jess.Defrule.fire(Defrule.java, Compiled Code)
        at jess.Activation.fire(Activation.java:65)
        at jess.Rete.run(Rete.java, Compiled Code)
        at jess.Rete.run(Rete.java, Compiled Code)
        at jess.HaltEtc.call(Funcall.java:1528)
        at jess.FunctionHolder.call(FunctionHolder.java:37)
        at jess.Funcall.execute(Funcall.java:240)
        at jess.Jesp.parseAndExecuteFuncall(Jesp.java:1585)
        at jess.Jesp.parseSexp(Jesp.java:185)
        at jess.Jesp.parse(Jesp.java, Compiled Code)
        at jess.Main.execute(Main.java, Compiled Code)
        at jess.Main.main(Main.java:28)

I was assuming that the number -60067621520002 was going to be treated as a
long,
because of type conversions, but it looks like the Jess parser is converting
it to a double
and then raising and exception because there is no NewThing constructor that
takes a double.

Question: How do you tell the Jess parser that this is a long value, as
opposed to a double or a string?
--------------------------------------------------------


Problem 2:
----------------

I came up with an answer for question 1, but my answer led to further
problems.
My solution was to explicitly create a long value, so that the parameter's
type is unambiguous:

;; begin file

        (defclass thing NewThing)

        (deffunction create-newthing (?value)
          (bind ?myval (call Long parseLong ?value))
          (definstance thing (new NewThing ?myval))
        )

        (defrule startup_rule
          =>
        (bind ?thing1 (create-newthing "-60067621520002"))
        )

        (reset)
        (run)

;;end file


This got rid of the exception from problem 1, but posed several another
issue.
I expected the following Rule1 would be matched and executed, but it was
not:

        (defrule Rule1
                (thing (value -60067621520002))
                =>
        )

Question 2: Knowing that slot values in Jess are typeless, how do I specify
a rule pattern that will
correctly match against NewThing objects?


Problem 3
---------------

My solution to problem 2 was to rewrite the rule above as follows:

        (defrule Rule1
                (thing (value ?myvalue&:(eq ?myvalue (call Long parseLong
"-60067621520002"))))
                =>
        )

This works, but I don't like it.  I don't have to do this for pattern
matching other Java native types
like strings or integers, so why here?  The whole approach seems more
complex than it needs
to be, so I'm looking for either 1) another approach or  2) verification
that this is what I have to do in this case.

Here's the code for NewThing.java:

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

public class NewThing  {
        
        private long m_value;


        public NewThing(long value) {
                m_value = value;
        }

        public void setValue(long value) {

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

        public long getValue() {
                return m_value;
        }

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

/*********** end code *******************/

----------
George Rudolph
Mad Scientist
Motorola SSG
----------

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