This example illustrates the use of user:term_expansion/[2,4] to
augment the built-in predicate expand_term/2, which works
as a filter on the input to compile and consult. The code
below will allow the declaration `:- wait f/3' as an alias
for `:- block f(-,?,?)'. Wait declarations were used in
previous versions of SICStus Prolog.
Note the multifile declaration, which prevents this
user:term_expansion/[2,4] clause from erasing any other
clauses for the same predicate that might have been
loaded.
:- op(1150, fx, [wait]).
:- multifile user:term_expansion/2.
user:term_expansion((:- wait F/N), (:- block Head)) :-
functor(Head, F, N),
wb_args(N, Head).
wb_args(0, _Head).
wb_args(1, Head) :- arg(1, Head, -).
wb_args(N, Head) :-
N>1,
arg(N, Head, ?),
N1 is N-1,
wb_args(N1, Head).