Get all Prolog Predicates


I want to get all predicates that are in the file.

?- get alle Predicates
Then I would get the result:

car(X,Y,[X|R],[Y|L]):- car(X,Y,R,L).
car(X,Y,[Z|R],[Z|L]):- dif(X,Z), car(X,Y,R,L).

I read somewhere about Prolog’s Introspection.
But I just found functor, arg, ?Term =… ?List etc.
Then I have to test every phrase in the file.
I hope there is a better solution?

Or do I have to program a parser?

Thank you

Axel Pfennig

I take you are self learning Prolog and using SWI-Prolog.

You should work though the online book Learn Prolog Now!.

Most of what you are using with your code is covered in the book, except dif/2 which is often used by more advanced Prolog users or the purist.


1 Like

I doubt it is the right answer, but possibly you are looking for source_file/2. No sane Prolog program should need this directly though. It is mainly there for writing tools that reason about programs.

1 Like

Thank you. My prolog program has to encode every predicate to a vector to find similar predicates. I will program a parser.