« Return to Thread: strings and atoms with JPL

Re: strings and atoms with JPL

by Paul Singleton :: Rate this Message:

Reply to Author | View in Thread

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 majordomo@...

 « Return to Thread: strings and atoms with JPL