I'm running queries against a generated set of facts, and some facts may not exist. When that happens, SWI Prolog errors out with e.g. Undefined procedure: 'LongIdent'/4
. Is there a way to get it to instead simply have the goal involving 'LongIdent'/4
fail?
1
votes
1 Answers
1
votes
Well you could change the default behavior using unknown/2 which is declared as unknown(-Old, +New)
, Old
is the old-current flag, New
is the new flag that you use:
?- unknown(trace,fail).
Warning: Using a non-error value for unknown in the global module
Warning: causes most of the development environment to stop working.
Warning: Please use :- dynamic or limit usage of unknown to a module.
Warning: See http://www.swi-prolog.org/howto/database.html
true.
?- a(1).
false.
But you see the warnings explaining that this may not be a good idea...
If you don't know the current/old flag you could use it like:
?- unknown(X,fail).
Warning: Using a non-error value for unknown in the global module
Warning: causes most of the development environment to stop working.
Warning: Please use :- dynamic or limit usage of unknown to a module.
Warning: See http://www.swi-prolog.org/howto/database.html
X = trace.
check(LongIdent(....) ). -> false if LongIdent/4 does not exist else call LongIdent/4
would this be ok?? - coder:- dynamic('LongIdent'/4).
. This tells Prolog that it's a real predicate or fact but may not have been asserted (yet). - lurker