I think Jack Kerkhof wrote:
> Hi,
> 
> I'm having some trouble translating a java snippet into Jess syntax.
> Specifically, is it feasible to write the following java in a rule RHS:
> 
>      TimeZone tz = TimeZone.getTimeZone("GMT-5:00");
>      tz.setID("EST");
>      TimeZone.setDefault(tz);
>      System.out.println (
>        new SimpleDateFormat("MMM dd yyyy kk:mm:ss zzz").format(new
> Date()));
> 
> 
> My futile attempts look something like:
> 
>  (bind ?tz (new java.util.TimeZone (call getTimeZone "GMT-5:00" )))
>  (call ?tz setID "EST")
>  (printout t "the date is "
>  (call format (new java.text.SimpleDateFormat "MMM dd yyyy kk:mm:ss
> zzz")
>                (new java.util.Date) )
>    crlf)
> ... and several permutations thereof, all of which fail miserably.


This isn't too bad. The trick is to do it one piece at a time, going
on to the next piece only after the first is figured out. In the
firsty line above you're creating a TimeZone object, when what you
want to call is a static method (no object required). In the last line
you've put the method name format before the object to call it
on. Fixed up  the code should look something like:

(import java.util.*)
(import java.text.SimpleDateFormat)

(bind ?tz (call TimeZone getTimeZone "GMT-5:00"))
(?tz setID "EST")
(call TimeZone setDefault ?tz)
(printout t (call (new SimpleDateFormat "MMM dd yyyy kk:mm:ss zzz")
                   format (new Date)) crlf)

> 
> 
> 1) Is this even possible in Jess? (I know some one line java calls work
> in JESS, but that's about it...)

In general, you can call pretty much anything using Jess's reflection 
interface.  Life starts to get tough if you need to work with Java
arrays, especially multidimensional ones or large ones.

> 2) What does the Jess syntax for the above look like?
> 3) Is there any documentation of Java->Jess syntax translation.(I have
> looked in the JESS doc and see some examples of java in jess, but no
> explicit definitions)

Look at the documentation for (call) and (new) for info about how to
make method calls and create objectsm, and see (set-member) and
(get-member) for member-variable access. Manual section 2.6 is the
closest thing to a general overview.

> 
> Thanks, Jack
> 
> PS The time zone code is to force EST no matter where this is run, and
> get around 'daylight savings time' features of the (somewhat obfuscated)
> date classes...
> 
> ---------------------------------------------------------------------
> 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