tl:dr - 我有一行 prolog,在一个版本的 Prolog (SWI) 中运行良好,但在另一个版本 (TuProlog) 中运行良好。
我正在将脚本从 SWI prolog 移植到 Tuprolog。(TuProlog 最近做了一个大更新,我在两个版本上都得到了相同的行为)
当我使用下面的 java 设置将脚本放入 TuProlog 时,我收到错误“无法将整个字符串读取为一个术语”。
所以我减少了脚本(有效地使用二进制搜索),直到我将脚本减少到:
iterm3(Term) --> "'", notquote(Cs), "'", { name(Term1,Cs), Term = q(Term1) }.
虽然 swipl 很好,但输出如下......
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).
?-
但仍然在 Tuprolog 中返回“无法将整个字符串读取为一个术语” - 谁能告诉我为什么会发生这种情况?
附录: 使用的代码:
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();
}
}