Re: strings and atoms with JPL

zli <[email protected]> Tue, 1 Jul 2014 22:45:41 -0700 (PDT)
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
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?
2. It seems that the string I get from prolog has a "'" before and after the
actual string, and I would need to strip the single quotes before using it.
Is this something I have to do or is there a way to get a Java string (so to
speak)?

Thanks much in advance!

Regards,
Zack


Paul Singleton wrote
> Victor NOEL wrote:
>> Hello,
>> 
>> I am wondering how can strings be used with JPL, and more
>> generally, what is the link between atoms and strings.
>> 
>> What I think is :
>> strings are atoms with " ' " before and after.
> 
> Then you are thinking of "quoted atoms", which are atoms
> whose names are quoted within a Prolog source text, perhaps
> because they would otherwise be misinterpreted or illegal:
> 
>    2+2 == +(2,2)
> 
> but
> 
>    '2+2' denotes an atom whose name has three characters.
> 
>> In JPL, there seems to be no distinction between a
>> string and a "classical" atom.
> 
> Nor is there in Prolog (except in input, output and source
> syntax).
> 
>> Are things like that ? Am I missing something ?
>> 
>> I am asking this because I am wondering if strings in JPL should
>> be treated differently than atoms or not, more specifically,
>> should I think that any string (used in the context of JPl of
>> course, in a term for example) *is* an atom ? Or is there a 
>> difference that make strings to be treated differently than atoms ?
> 
> JPL's jpl.Term class and its subclasses provide an alternative
> concrete syntax for Prolog, in which atom names such as 2+2 do
> not need to be quoted as above, hence
> 
>    new jpl.Atom("2+2")
> 
> creates an atom identical to that denoted, in Prolog source, by
> '2+2'.  I trust the need for double quotes is understood ;-|
> 
> Of course, if you use JPL's convenience methods to create terms
> from Prolog source fragments, then you'll still need to quote
> such atoms, e.g.
> 
>    jpl.Query.oneSolution("assert(is_an_atom('2+2'))")
> 
> 
>> Thanks you for your help :)
>> 
>> Victor
> 
> regards - Paul Singleton
> 
> 
> ------------
> For further info, please visit http://www.swi-prolog.org/
> 
> To unsubscribe, send a plaintext mail with "unsubscribe prolog 
> <e-mail>
> "
> in its body to 

> [email protected]





--
View this message in context: http://swi-prolog.996271.n3.nabble.com/strings-and-atoms-with-JPL-tp5446p14955.html
Sent from the SWI Prolog mailing list archive at Nabble.com.