shithub: pprolog

Download patch

ref: 68c6243c889783deedfee5f77317d45057a236ee
parent: 3e1e9621d1f19b221d59191ed55e78b171a5fe93
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Wed Jul 7 11:54:07 EDT 2021

Make arg/3 work according to spec

--- a/builtins.c
+++ b/builtins.c
@@ -372,18 +372,23 @@
 	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)
+
+	if(n->ival > term->arity)
 		return 0;
-	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);
 }