Hi Ernest,
Great suggestion! It returned type "LONG". I can see the JessLong class
that implements the Jess function long does not list RU.Long as a type
to be converted, and I must admit I'm a bit perplexed by this. The
tooltip documentation for the long function states that Jess now allows
long literals. My reason for using the long function was to convert the
data from a variable of some type (usually float but now obviously
sometimes a long) to a long to be passed to a Java method. The Java
method expects a Java long (primitive type) and I'm using Java 5. Is
this function no longer needed for this usage with Jess 7 onwards?
In any case, I now have several ideas how to fix this.
For completeness, here is an example showing the behavior and use of
Long.longValue():
(deftemplate x "blah"
(slot name)
(slot num (type FLOAT))
(slot numConverted (default 0)(type LONG))
)
(defrule convertJessLong
?xfact <- (x (num ?num) (numConverted ?numConv&:(= ?numConv 0)))
=>
(printout t "The value is of type " (jess-type ?num) crlf)
(modify ?xfact (numConverted (long ?num)) ))
(reset)
(assert (x (name "long from Java Long.longValue")(num ((new Long
1157650583) longValue))))
--
Jess, the Rule Engine for the Java Platform
Copyright (C) 2008 Sandia Corporation
Jess Version 7.1p2 11/5/2008
MAIN::convertJessLong: +1+1+1+t
==> Focus MAIN
==> f-0 (MAIN::initial-fact)
==> f-1 (MAIN::x (name "long from Java Long.longValue") (num
1157650583) (numConverted 0))
==> Activation: MAIN::convertJessLong : f-1
FIRE 1 MAIN::convertJessLong f-1
The value is of type LONG
Jess reported an error in routine long
while executing (long ?num)
while executing (modify ?xfact (numConverted (long ?num)))
while executing defrule MAIN::convertJessLong
while executing (run).
Message: Illegal argument 1157650583.
Program text: ( run ) at line 48 in file
C:\dev\BrianSamples\src\debug-jess-long\testJessLong.clp.
f-0 (MAIN::initial-fact)
f-1 (MAIN::x (name "long from Java Long.longValue") (num 1157650583)
(numConverted 0))
For a total of 2 facts in module MAIN.
Thanks,
Brian
-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Ernest Friedman-Hill
Sent: Monday, June 08, 2009 5:41 PM
To: jess-users
Subject: Re: JESS: JessLong Illegal argument exception
On Jun 8, 2009, at 8:19 PM, Brian Rogosky wrote:
> Hello,
> I'm experiencing an "Illegal Argument" exception when calling the
> "long" function.
Hi Brian,
It'll only throw that exception if the argument isn't a number,
string, or symbol. For example, a list value with a single number in
it would produce the error you're seeing; the list would display
without parens in the error message:
Jess> (long (list 123))
Jess reported an error in routine long
while executing (long (list 123)).
Message: Illegal argument 123.
Program text: ( long ( list 123 ) ) at line 1.
Since it looks like you are able to add a debug print at the point of
failure, try something like
(printout t "The bad value is of type " (jess-type ?city) crlf)
If it prints anything other than INTEGER, FLOAT, STRING, SYMBOL, or
FACT, then there's the problem.
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
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].
--------------------------------------------------------------------
--------------------------------------------------------------------
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].
--------------------------------------------------------------------