GNU Prolog term-expansion is currently limited. But you can use Logtalk (which supports GNU Prolog) term-expansion mechanism to achieve that transformation. In a nutshell, define a Logtalk hook object with your expansion rules and then expand your Prolog source files, by using the logtalk_compile/2
predicate. Something like:
:- object(my_expansion,
implements(expading)).
term_expansion((:- web_resource(Name/Arity, Headers) Clauses) :-
% construct clauses
...
:- end_object.
and then:
$ gplgt
...
| ?- {my_expansion}.
...
| ?- logtalk_compile('my_source_file.pl', [hook(my_expansion), scratch_directory('.']).
...
The last query will result in a new Prolog file saved in the current directory with the expansion results. You can them compile this file using gplc
as usual. For more details on the portable Logtalk term-expansion mechanism see:
https://logtalk.org/manuals/userman/expansion.html