Re: help

From: Andrew John Sadler <ajs2_at_icparc.ic.ac.uk>
Date: Mon 21 Jul 2003 09:36:49 AM GMT
Message-Id: <E19eX69-0004RN-00@tempest.icparc.ic.ac.uk>
> Envelope-to: eclipse-bugs@icparc.ic.ac.uk
> Delivery-date: Mon, 21 Jul 2003 04:14:10 +0100
> Date: Sun, 20 Jul 2003 20:12:58 -0700 (MST)
> From: "Tuan C. Le" <lctuan@asu.edu>
> X-Sender: lctuan@general2.asu.edu
> Cc: "Tuan C. Le" <lctuan@asu.edu>, j.schimpf@ic.ac.uk,
>  eclipse-bugs@icparc.ic.ac.uk
> Content-type: TEXT/PLAIN; charset=US-ASCII
> 
> 
> Hi again,
> 
> I was able to call IC library from Java, but I don't know how to get the
> values of variables back. For example, I could use rpc to call:
> 
> eclipse.rpc(
> 	"lib(ic), ic:(T >= 0), ic:(470.0 * T+1773.0 =:= 6830.0),flush(output)"
> 	);
> 
> But cannot get the value of T from Java, although I used CompoundTerm
> structure. Can you help showing me on getting the value of T. I may not use
> CompoundTerm correctly.
> 
> Thanks,
> .Tuan.
> 
> 

This should work for you...

    CompoundTerm result = eclipse.rpc("lib(ic), ic:(T >= 0), ic:(470.0 * T+1773.0 =:= 6830.0),flush(output)");

    // The top-level functor of the goal term is "," (a conjunction)
    // The first argument is "lib(ic)"
    // The second argument is the conjunction of the remaining goals.
    CompoundTerm secondConjunction = (CompoundTerm) result.arg(2);

    // the second goal "ic:(T >= 0)" is the first argument of this conjunction
    CompoundTerm secondGoal = (CompoundTerm) secondConjunction.arg(1);

    // The canonical form of this goal is :(ic, >=(T,0))
    // so to access the variable T you need the first argument of
    // the second argument
    Object tValue = ((CompoundTerm)secondGoal.arg(2)).arg(1);

    System.out.println("T = "+tValue);

The above code was modified from an example given in the "Embedding
and Interfacing Maunal", in which you will find other ways to transfer
values to and from Java.

If you continue to use RPC, it will make things easier for you if you
adopt some form of convention where by the variables you want to
access always appear in the first argument position. eg.

    CompoundTerm result = eclipse.rpc("T=T, lib(ic),ic:(T>=0),"...);

then you can access the value as

    CompoundTerm tValue = ((CompoundTerm)result.arg(1)).arg(1);

Hope that helps

Andrew Sadler
Received on Mon Jul 21 10:36:52 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:08:24 PM GMT GMT