1

Suppose I have the following code, which prints It works! if a term is a string using the predicate string/1:

Term string = org.jpl7.Util.textToTerm("\"test\"");
Query testQuery = new Query("string",string);

if(testQuery.hasMoreSolutions()) {
    System.out.println("It works!");
}

This does not print anything, which is not what I expected.

Even more strange, replacing the query with new Query("atom",string) now does work properly, which mean that string is passed as an atom instead of an SWI-Prolog 7 string, even though the text I gave the JPL library to parse uses the double quotes which are the string delimiters, not the atom delimiters.

What's even weirder is that the Java debugger tells me that the Term string has name test (without the quotes) and type string! So textToTerm seems to produce a string which is correct, but the Term itself is passed as an atom anyway!

Is that a bug, or is it default behavior?

EDIT: the JPL 7 docs states that

SWI Prolog V7 strings are represented in JPL7 as Atoms whose type is "string"

So is there just no way to actually pass real strings to queries?

Fatalize
  • 3,513
  • 15
  • 25
  • 1
    From the [JPL release notes](http://jpl7.org/): _"SWI Prolog V7 strings are represented in JPL7 as Atoms whose type is "string"; ..."_ Would it be feasible for you to just accept the atom, and use [atom_string/2](http://www.swi-prolog.org/pldoc/man?section=strings#atom_string/2) to convert it to string? – Ruud Helderman Sep 20 '15 at 20:57
  • @Ruud It could be doable, but that's cumbersome. I can't believe that the JPL is this bad, which is primarily why I asked. – Fatalize Sep 21 '15 at 07:37

0 Answers0