Home > Archive > Prolog > March 2005 > Another newbie question...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Another newbie question...
|
|
| Eddie Jobson 2005-03-04, 4:00 pm |
| Is it possible to write a prolog routine which will create a list
containing all the clauses in a program? I've tried without success a
combination of 'setof' and 'clause'... any suggestions?
Thanks in advance.
| |
| Brian Hulley 2005-03-04, 4:00 pm |
|
Eddie Jobson wrote:
> Is it possible to write a prolog routine which will create a list
> containing all the clauses in a program? I've tried without success a
> combination of 'setof' and 'clause'... any suggestions?
You could try a query such as:
?- current_predicate(Functor/Arity), functor(Head, Functor, Arity),
(predicate_property(Head, built_in)->true; clause(Head,Body)).
This will list everything in the database as long as it is not a built
in predicate (in SWI Prolog at least). However you have to be careful
since some predicates may not allow you to inspect them, and you would
then get an exception.
| |
| Brian Hulley 2005-03-04, 4:00 pm |
|
Brian Hulley wrote:
> Eddie Jobson wrote:
a[color=darkred]
>
> You could try a query such as:
>
> ?- current_predicate(Functor/Arity), functor(Head, Functor, Arity),
> (predicate_property(Head, built_in)->true; clause(Head,Body)).
It should be ->fail not ->true in the above, and you'd also need to
deal with other kinds of non-user-program predicates such as foreign
predicates etc.
|
|
|
|
|