Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

Questions about Prolog

  • Q: How do I find out, in which file(s) a predicate is actually defined?
  • A: This can be simply done by using the built-in predicate_property/2 with the property file(FileName).
/* * * * predicate_in_file(Head, File) * * * * 
 *  Example:
 *   ?- predicate_in_file(Head, 'd:/workspaces/runtime-eclipseapplication/pop/').
 *   Head = predicate_in_file(_, _) ;
 *   false. 

predicate_in_file(Head, File):-
  predicate_property(Head, file(File)).

Note: In case of “multifile” predicates (whose clauses are unioned from the contents of multiple files) the above gives the name of just one file, not of all :-( If you don't know what multifile predicates are and how to work with them, see the SWI-Prlog manual1).


  • listing(my_predicate/3) gives me the implementation of my_predicate with 3 parameters.
Just type “help.” in the prolog console nd then “multifile” in the interactive manpage.
teaching/labs/xp/2009a/prolog_questions.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019