diff options
-rw-r--r-- | builtins.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -372,18 +372,23 @@ builtinarg(Term *goal, Binding **bindings, Module *module) Term *term = n->next; Term *arg = term->next; + if(n->tag == VariableTerm || term->tag == VariableTerm) + Throw(instantiationerror()); if(n->tag != IntegerTerm) - return 0; + Throw(typeerror(L"integer", n)); + if(term->tag != CompoundTerm) + Throw(typeerror(L"compound", term)); if(n->ival < 0) Throw(domainerror(L"not_less_than_zero", n)); - if(term->tag != CompoundTerm) - return 0; - if(n->ival >= term->arity) + + if(n->ival > term->arity) return 0; + print("Passed checks!\n"); + int i; Term *t; - for(i = 0, t = term->children; i < n->ival; i++, t = t->next); + for(i = 1, t = term->children; i < n->ival; i++, t = t->next); return unify(arg, t, bindings); } |