开发者

accessing prolog list term

开发者 https://www.devze.com 2023-04-12 15:05 出处:网络
I\'ve been using jpl for calling prolog from java. I\'m using the followi开发者_Python百科ng code in java to get the value of X from prolog.

I've been using jpl for calling prolog from java. I'm using the followi开发者_Python百科ng 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消