# Get all Prolog Predicates

**URL:** <https://swi-prolog.discourse.group/t/get-all-prolog-predicates/3066>\
**Category:** Predicate\
**Created:** [October 19, 2020, 9:41am UTC](https://swi-prolog.discourse.group/t/get-all-prolog-predicates/3066 "2020-10-19T09:41:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrologAxel](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PrologAxel](https://swi-prolog.discourse.group/u/PrologAxel)\
**Post date:** [October 19, 2020, 9:41am UTC](https://swi-prolog.discourse.group/t/get-all-prolog-predicates/3066/1 "2020-10-19T09:41:23Z")

</div>

Hello.

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

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

```prolog
car(_,_,[],[]).
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

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [October 19, 2020, 9:48am UTC](https://swi-prolog.discourse.group/t/get-all-prolog-predicates/3066/2 "2020-10-19T09:48:47Z")

</div>

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

You should work though the online book [Learn Prolog Now!](http://www.learnprolognow.org/).

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.

HTH

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 19, 2020, 10:38am UTC](https://swi-prolog.discourse.group/t/get-all-prolog-predicates/3066/3 "2020-10-19T10:38:42Z")

</div>

> [@PrologAxel](#):
>
> I want to get all predicates that are in the file.

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.

---

<div class="post-metadata">

**Author:** ![PrologAxel](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PrologAxel](https://swi-prolog.discourse.group/u/PrologAxel)\
**Post date:** [October 20, 2020, 8:15pm UTC](https://swi-prolog.discourse.group/t/get-all-prolog-predicates/3066/4 "2020-10-20T20:15:50Z")

</div>

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