return engine.fail();
}
} else if (a1.isVariable()) {
a2 = a2.dereference();
if (a2.isVariable()) {
throw new PInstantiationException(this, 2);
} else if (a2.equals(SYM_NIL)) {
throw new IllegalDomainException(this, 2, "non_empty_list", a2);
} else if (!a2.isList()) {
throw new IllegalTypeException(this, 2, "list", a2);
}
Term head = ((ListTerm) a2).car().dereference();
Term tail = ((ListTerm) a2).cdr().dereference();
if (head.isVariable()) {
throw new PInstantiationException(this, 2);
}
if (tail.equals(SYM_NIL)) {
if (head.isSymbol() || head.isNumber() || head.isJavaObject()
|| head.isClosure()) {
if (!a1.unify(head, engine.trail)) {
return engine.fail();
}
return cont;
} else {
throw new IllegalTypeException(this, 2, "atomic", head);
}
}
if (!head.isSymbol()) {
throw new IllegalTypeException(this, 2, "atom", head);
}
Term x = tail;
while (!x.equals(SYM_NIL)) {
if (x.isVariable()) {
throw new PInstantiationException(this, 2);
}
if (!x.isList()) {
throw new IllegalTypeException(this, 2, "list", a2);
}
x = ((ListTerm) x).cdr().dereference();