On Thu, 15 Apr 2010, david wrote: > For example, assume foo/1 is a dynamic predicate, and that there are > rules such as: > > foo(X) :- goo(X). > > Is there a way to test if there are any assertions of foo/1? One would > want to avoid any "false positives" due to, say, goo/1 being satisfied. If you don't care about side effects of goo/1 and just want to know whether foo(X) succeeds with a specific, not general, value of X, then you could do this: specific_foo(X):- foo(Y),Y==X. Note that specific_foo(bar) will succeed with foo(X):-goo(X). goo(bar). If you want to test for the existence of a clause with exactly foo(bar) as its head, not any variable, you could do this: head_foo(X):- clause(foo(Y):-_),Y==X. Note that head_foo(bar) will succeed with foo(bar):-fail. It *only* looks at the head. If you want to test explicitly for a fact with no body, you could do this: fact_foo(X):- clause(foo(Y):-true),Y==X. That succeeds with foo(bar) but not with foo(bar):-goo(bar). It should be easy to imagine other variations of using clause/1 and ==/2 depending on just what you want to query for. Note that all of these break the logic programming model and you probably should think hard about whether what you're attempting to do is *really* a good idea. -- Matthew Skala, postdoctoral researcher, Universities of Toronto and Waterloo mskala_at_...203... mskala@...205... mskala@...206...Received on Thu Apr 15 2010 - 13:57:20 CEST
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST