Given the following tuple of directive + predicate:
:- web_resource(plaintext/1, [content_type(text/plain)]).
plaintext(Result) :-
...code...
how do I tell gplc to transform this code into
plaintext([headers(['Content-Type'-'text/plain']),
payload(Payload)]) :-
old_plaintext(Payload).
old_plaintext(Payload) :-
...code...
before compiling it? old_payload can be defined recursively.
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/2predicate. Something like:and then:
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
gplcas usual. For more details on the portable Logtalk term-expansion mechanism see: https://logtalk.org/manuals/userman/expansion.html