简体   繁体   English

访问序言列表词

[英]accessing prolog list term

I've been using jpl for calling prolog from java. 我一直在使用jpl从Java调用prolog。 I'm using the following code in java to get the value of X from 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"));

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. 我现在想做的是从解决方案中获取值2并将其加倍。 Can anyone help me how to handle that? 谁能帮我解决这个问题?

oneSolution() returns a hashtable of variablename-to-term bindings ( they say ). oneSolution()返回变量名到术语绑定的哈希表( 他们说 )。 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. 另请参阅Term的文档。

Edit: fixed mistakes 编辑:修正错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM