Re: strings and atoms with JPL

Paul Singleton <[email protected]> Wed, 02 Jul 2014 10:55:47 +0100
Newsgroups gmane.comp.ai.prolog.swi
Organization Jambusters Ltd
Message-ID <[email protected]>
On 02/07/2014 06:45, zli wrote:
> Hi Paul,
>
> I'm new to Prolog and am using JPL to get some string outputs. Here is an
> example.
>
>     Query query = new Query("getSomeString(someInput, Output)");
>     // In prolog, Output = 'This is my output string'.
>     Term term = (Term) query.oneSolution().get("Output");
>     String outputString = term.toString();
>
> 1. Is this the correct way to get my output?

No; toString is for debugging only (helpfully adds quotes)

Use Term#name to get the name of an atom or compound, e.g.

   java.util.Hashtable soln = 
jpl.Query.oneSolution("current_prolog_flag(arch, Arch)");
   jpl.Term arch = (jpl.Term) soln.get("Arch");
   String name = arch.name();
   System.out.println("arch=" + name);

which writes

   arch=i386-win32

Regards

Paul Singleton