Did you know ... Search Documentation:
gpp.pl -- Use XSB gpp preprocessor
PublicShow source

This library enables using the XSB gpp preprocessor on .P files. Currently the gpp program is not provided with SWI-Prolog. If you need this compatibility get it from XSB. The XSB sources provide gpp.c, a simple stand alone C file that can be compiled with any C compiler. The gpp program must be installed in a directory accessible through the PATH environment variable. The preprocessor is enabled using

:- use_module(library(dialect/xsb/gpp)).

Running code through gpp can be useful for several reasons:

  • Share (numeric) constants with C code. Note that SWI-Prolog's ffi pack provides an alternative for this.
  • Provide a source translation mechanism that appeals more to e.g., C programmers and can deal with partial Prolog expressions and/or syntax that is illegal to some Prolog implementation.
  • Load legacy XSB programs.

There are also good reasons not to use a preprocessor:

  • gpp doesn't propagate source locations, so error messages typically report the wrong location.
  • If #include file is used it will report the wrong file for errors. In addition, make/0 will not be able to pick up that an included file has changed and thus the main file needs to be reloaded.
  • Wrong source locations also imply tools such as edit/1 or the graphical debugger no longer work.
  • Advanced tooling such as PceEmacs cannot correctly highlight code that uses the preprocessor.
Source prolog:open_source_hook(+Path, -Stream, +Options)[multifile]
Implementation of the open source hook to use the XSB gpp preprocessor on .P files. This requires gpp on the PATH environment variable.