3

tl:dr - I have a single line of prolog, that works fine in one version of Prolog (SWI) but not in another (TuProlog).

I'm porting a script from SWI prolog, to Tuprolog. (TuProlog recently did a big update and I get the same behaviour on both versions)

When I put the script into TuProlog using the java setup below I get the error "The enitire string could not be read as one term".

So I cut down the script (effectively using binary search) until I reduce the script to:

iterm3(Term) --> "'", notquote(Cs), "'", { name(Term1,Cs), Term = q(Term1) }.

Which goes though swipl fine, with the following output...

cobrakai:~ josephreddington$ swipl -s /Users/josephreddington/Documents/workspace/com.plancomps.prolog.helloworld/caml-light-dynamics/Tools/Prolog/temp.pl% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,992 bytes% /Users/josephreddington/Documents/workspace/com.plancomps.prolog.helloworld/caml-light-dynamics/Tools/Prolog/temp.pl compiled 0.00 sec, 1,720 bytes
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.5)
Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- 

But still returns "The enitire string could not be read as one term" in Tuprolog - can anyone tell me why this might be happening?

APPENDIX: CODE USED:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import alice.tuprolog.NoMoreSolutionException;
import alice.tuprolog.NoSolutionException;
import alice.tuprolog.Prolog;
import alice.tuprolog.SolveInfo;
import alice.tuprolog.Theory;

public class EntireStringForStackOverflow {
    public static void main(String[] args) throws Exception {
        Prolog engine = new Prolog();
        engine.loadLibrary("alice.tuprolog.lib.DCGLibrary");
        engine.addTheory(new Theory(readFile("temp.pl")));
    }

    private static String readFile(String file) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = null;
        StringBuilder stringBuilder = new StringBuilder();
        String ls = System.getProperty("line.separator");
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append(ls);
        }
        return stringBuilder.toString();
    }
}
false
  • 10,264
  • 13
  • 101
  • 209
Joe
  • 4,367
  • 7
  • 33
  • 52

2 Answers2

0

I guess could be that the single quote needs to be quoted in Tuprolog. I would try

iterm3(Term) --> "\'", notquote(Cs), "\'", { name(Term1,Cs), Term = q(Term1) }.

edit Now I must admit I don't know where the documentation of tuProlog DCGs could be, and also I can't spent too much searching it (I could read it, actually). Another modification to your grammar, where you can see why I suggested the useless modification above:

iterm3(Term) --> ['\''], notquote(Cs), ['\''], { name(Term1,Cs), Term = q(Term1) }.

That is, verify by try-and-fail if double quotes constants are forbidden in tuProlog...

CapelliC
  • 59,646
  • 5
  • 47
  • 90
0

Generally speaking, the correct way to write terms containing single quotes in tuProlog is the upper one, that is, "'" (or, just to provide another mixed example, "a'b"). However, such terms are currently unhandled by the DCG Library

Enrico
  • 1