Converts a proper list to an array of terms, else throws an exception @param t the Term representing a list @throws JPLException if the term passed is not itself a Prolog list term @return an array of terms whose successive elements are the corresponding members of the list (if it is a list)
(Term t)
| 1061 | * @return an array of terms whose successive elements are the corresponding members of the list (if it is a list) |
| 1062 | */ |
| 1063 | public static Term[] listToTermArray(Term t) { |
| 1064 | int len = Term.listLength(t); // exception if not a well formed list |
| 1065 | if (len < 0) { |
| 1066 | throw new JPLException("term is not a proper list"); |
| 1067 | } |
| 1068 | Term[] ts = new Term[len]; |
| 1069 | for (int i = 0; i < len; i++) { // no need to check functor (it's a list) |
| 1070 | ts[i] = t.arg(1); |
| 1071 | t = t.arg(2); |
| 1072 | } |
| 1073 | return ts; |
| 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * Converts a proper list to an array of terms, else throws an exception |