I think Rudolph George-P27574 wrote:
> I'm using Jess 5.0b4 and JDK 1.2.2 on NT 4.0.
> 
> I have some code that supports a GUI rule editor.
> The code gets a defrule from the engine, then parses the rule 
> using methods available from the Defrule object.
> In processing the right-hand-side of a rule,
> it looks for strings, variables, or function calls.

Note that a RHS always consists of a list of Funcalls, never anything
else. You can fetch them one at a time with Defrule.getAction().

> When processing a particular Funcall object,
> it uses the RU arg types to distinguish argument types and know 
> how to further process them (like RU.STRING, RU.VARIABLE, RU.FUNCALL).
> (Note: I did not write this code, but I do have to maintain it.)
> 
> I had assumed that each kind of arg or Value object would have only one
> type--
> i.e. the RU types are mutually exclusive. 

They are, and even their bits are mutually exclusive. You can always
use '|' to combine them and then test using '&'. In this particular
case, RU.FUNCALL == 64, RU.STRING = 2. 

 However, I have run into a case
> where
> in the code snippet
>       
>       //myFunc is a Funcall that is passed in...
>       jess.Value arg = myFunc.get(i);
> 
>       if (arg.type() == jess.RU.FUNCALL) {
>               Funcall func = arg.funcallValue(context);
>               tempstr = func.toString();
>               System.out.println(" func = " + func.toString());
>       }
> 
>             if(arg.type() == jess.RU.STRING) {
>               tempstr = arg.stringValue(context);
>               System.out.println(" string = " + tempstr);
> }
> 
> both clauses seem to be getting executed for the same arg.
> 

Given only the exact code shown here, this can't happen. The
implementation of Value.type() is just

  public int type()
  {
    return m_type;
  } 

m_type is private, and Value is an immutable class.

> The case involves an action like 
>       (do-this ?param1  (strcat "string1 "  (call warper warp ?myObject)
> " string2"))
> 
> where the call to warper.warp() returns a String.
> Relating to the snippet above, the strcat call is the value of "myFunc", and
> the (call warper warp ?myObject) is the value of "arg".
> 
> Question 1. Is this the type confusion a bug?

I don't think so. Note, though, that arg.funcallValue(c) and
arg.stringValue(c) will both return something: stringValue(c) will
execute the function and attempt to return the result as a
String. Although the calls of type() would seem to prevent this
happening in the code above, perhaps there's something you're not
showing me that's crucial. Note also that arg = arg.resolveValue(c)
will replace the Funcall object with its String result, and perhaps
this is being done somewhere.

Maybe if I saw a longer stretch of code I could tell what was
happening. 

> Question 2. Is there an easier way to parse defrules (back) out of the
> engine than what is being done? 
> 

Depends on exactly what you're trying to do, I suppose. The Funcall
data structure is a straightforward representation of a function call,
so I'm not sure what could be simpler. The Pattern objects are
somewhat messier, but they will likely improve in the future.


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