访问序言列表术语

发布于 2024-12-08 20:50:20 字数 388 浏览 9 评论 0原文

我一直在使用 jpl 从 java 调用 prolog。我在 java 中使用以下代码从 prolog 中获取 X 的值。

String t4 = "myNumber(X)";
Query q4 = new Query(t4);
System.out.println( "first solution of " + t4 + ": X = " + q4.oneSolution().get("X"));

我的解决方案是——

first solution of myNumber(X): X = '.'(2, [])--which is true.

我现在想做的是从解决方案中获取值 2 并将数字加倍。 谁能帮我解决这个问题吗?

I've been using jpl for calling prolog from java. I'm using the following code in java to get the value of X from prolog.

String t4 = "myNumber(X)";
Query q4 = new Query(t4);
System.out.println( "first solution of " + t4 + ": X = " + q4.oneSolution().get("X"));

And my solution is--

first solution of myNumber(X): X = '.'(2, [])--which is true.

What i wanted to do now is to obtain the value 2 from the solution and double the number.
Can anyone help me how to handle that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆蝶 2024-12-15 20:50:20

oneSolution() 返回变量名到术语绑定的哈希表 (他们说)。然后你必须检查该术语(未经测试):

Term listTerm = q4.oneSolution().get("X");
Term firstListItem = listTerm.arg(1);
double value = firstListItem.doubleValue(); // alternatively, use intValue() or so

还要检查 Term 的文档。

编辑:修正错误

oneSolution() returns a hashtable of variablename-to-term bindings (they say). Then you have to inspect to the term (untested):

Term listTerm = q4.oneSolution().get("X");
Term firstListItem = listTerm.arg(1);
double value = firstListItem.doubleValue(); // alternatively, use intValue() or so

Also check Term's documentation.

Edit: fixed mistakes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文