ref: c8867502df27f516b0d46b1a254f0da572bdadb6
parent: 3f316c5c9265618fe7095cc39c4cb10909cbe468
author: Peter Mikkelsen <[email protected]>
date: Fri Jul 16 16:22:40 EDT 2021
Handle the 'unknown' prolog flag correctly
--- a/eval.c
+++ b/eval.c
@@ -40,8 +40,32 @@
}else{
Predicate *pred = findpredicate(module->predicates, goal);
if(pred == nil){
- print("No predicate matches: %S:%S\n", module->name, prettyprint(goal, 0, 0, 0, nil));
- goto Backtrack;
+ Rune *name;
+ int arity;
+ Term *replacement = nil;
+ Term *procedure;
+ Term *pi;
+ if(goal->tag == CompoundTerm){
+ name = goal->text;
+ arity = goal->arity;
+ }else{
+ name = prettyprint(goal, 0, 0, 0, nil);
+ arity = 0;
+ }
+ switch(flagunknown){
+ case UnknownError:
+ procedure = mkatom(name);
+ procedure->next = mkinteger(arity);
+ pi = mkcompound(L"/", 2, procedure);
+ replacement = existenceerror(L"procedure", pi);
+ break;
+ case UnknownWarning:
+ print("Warning: no such predicate in module %S: %S/%d\n", module->name, name, arity);
+ case UnknownFail:
+ replacement = mkatom(L"fail");
+ }
+ goalstack = addgoals(goalstack, replacement, module);
+ continue;
}
/* Find a clause where the head unifies with the goal */