Converts a (JPL) list of Name=Var pairs (as yielded by atom_to_term/3) to a Map from Prolog variables (necessarily in term_t holders) to named JPL Variables @param nvs A JPL list of Name=Var pairs (as yielded by atom_to_term/3) @return Map A Map from Prolog variables (necessarily in term
(Term nvs)
| 95 | * @return Map A Map from Prolog variables (necessarily in term_t holders) to named JPL Variables |
| 96 | */ |
| 97 | public static Map<term_t, Variable> namevarsToMap(Term nvs) { |
| 98 | try { |
| 99 | Map<term_t, Variable> vars_to_Vars = new HashMap<term_t, Variable>(); |
| 100 | // while (nvs.isListPair() && nvs.arg(1).hasFunctor("=", 2)) { |
| 101 | while (nvs.arity() == 2 |
| 102 | && (nvs.name().equals(JPL.LIST_PAIR_MODERN) || nvs.name().equals(JPL.LIST_PAIR_TRADITIONAL)) |
| 103 | && nvs.arg(1).hasFunctor("=", 2)) { |
| 104 | // the cast to Variable is necessary to access the (protected) |
| 105 | // .term_ field |
| 106 | vars_to_Vars.put(((Variable) nvs.arg(1).arg(2)).term_, new Variable(nvs.arg(1).arg(1).name())); // map |
| 107 | // the |
| 108 | // Prolog |
| 109 | // variable |
| 110 | // to |
| 111 | // a |
| 112 | // new, |
| 113 | // named |
| 114 | // Variable |
| 115 | nvs = nvs.arg(2); // advance to next list cell |
| 116 | } |
| 117 | // maybe oughta check that nvs is [] ? |
| 118 | return vars_to_Vars; |
| 119 | } catch (java.lang.ClassCastException e) { // nvs is not of the expected |
| 120 | // structure |
| 121 | return null; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Converts a Prolog source text (as a String) to a corresponding JPL Term |
no test coverage detected