From 68c6243c889783deedfee5f77317d45057a236ee Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 7 Jul 2021 15:54:07 +0000 Subject: Make arg/3 work according to spec --- builtins.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'builtins.c') diff --git a/builtins.c b/builtins.c index 8215930..7c20b17 100644 --- a/builtins.c +++ b/builtins.c @@ -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); } -- cgit v1.2.3