summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 20:22:40 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-16 20:22:40 +0000
commitc8867502df27f516b0d46b1a254f0da572bdadb6 (patch)
tree6c760e19698a96d35fceb7a6381e25b744199c3b
parent3f316c5c9265618fe7095cc39c4cb10909cbe468 (diff)
Handle the 'unknown' prolog flag correctly
-rw-r--r--eval.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 6fec2b6..f957553 100644
--- a/eval.c
+++ b/eval.c
@@ -40,8 +40,32 @@ evalquery(Term *query)
}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 */