tl:dr -我有一行prolog,在一个版本的Prolog (SWI)中工作得很好,但在另一个版本(TuProlog)中却不行。
我正在将一个脚本从SWI prolog移植到Tuprolog。(TuProlog最近做了一个很大的更新,我在这两个版本上都有相同的行为)
当我使用下面的java设置将脚本放入TuProlog时,我会得到一个错误:“不能将enitire字符串作为一个术语读取”。
因此,我减少了脚本(有效地使用二进制搜索),直到我将脚本缩减为:
iterm3(Term) --> "'", notquote(Cs), "'", { name(Term1,Cs), Term = q(Term1) }.这虽然很好,但是有以下输出..。
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中的“enitire字符串不能作为一个术语读取”--有人能告诉我为什么会发生这种情况吗?
附录:使用的代码:
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();
}
}发布于 2013-07-22 15:05:24
我猜可能需要在Tuprolog中引用单引号。我会试着
iterm3(Term) --> "\'", notquote(Cs), "\'", { name(Term1,Cs), Term = q(Term1) }.现在我必须承认,我不知道tuProlog DCGs的文档可能在哪里,而且我也不能花费太多的时间搜索它(实际上,我可以阅读它)。对语法的另一个修改,您可以理解为什么我建议进行上述无用的修改:
iterm3(Term) --> ['\''], notquote(Cs), ['\''], { name(Term1,Cs), Term = q(Term1) }.也就是说,如果在tuProlog中禁止双引号常量,请尝试和失败进行验证.
发布于 2013-12-06 13:41:50
一般来说,在tuProlog中编写包含单引号的术语的正确方法是上面的方法,即“‘’”(或者仅仅提供另一个混合示例"a'b")。但是,DCG库目前无法处理这些术语。
https://stackoverflow.com/questions/17784581
复制相似问题