I think Rudolph George-P27574 wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> 
> 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?

My intention was that you'd use the new function (long <string>) to
enter long literals -- i.e., (long "123"). Yes, it's ugly, but as I
said, this release only has partial support for longs. The parser
can't parse long literals directly, and this can't be changed without
slowing things down for all non-long numeric literals until I rewrite
the whole thing. I'd like to do this eventually but it won't happen
for 5.0.


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

(thing (value ?X&=(long "12345"))) should work and is somewhat less
ugly than (thing (value ?X&:(eq ?X (long "12345")))). 

Type conversions are done when calling Java functions, (i.e., creating
the shadow fact from an object) but not during pattern matching. This
often bites people who expect symbols and Strings to compare equal,
but they don't: the types of the two Value objects being compared must
be the same.


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



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