If the inlined predicate has multiple clauses, they will be inlined in the form of a disjunction (note that indexing will be preserved).
If inlining is applied to an exported predicate, one must be aware that the definition will be textually substituted for the original goal in an unknown module context. Although the expansion mechanism will add module qualifications to the expanded source, it means that all predicates called by the expanded source must be exported from their definition module in order to be accessible from elsewhere.
The inline/1 directive must be issued from the definition module of Pred, and should occur before Pred's definition. Only calls that textually follow the definition will be inlined.
Note that inline/1 is a special system-defined case of inline/2, using a transformation predicate called unfold/6. Therefore get_flag(Pred, inline, unfold/6) can be used to test whether a predicate has been declared with inline/1.
Inlining can be disabled for debugging purposes by adding
:- pragma(noexpand).to the code containing calls, or by setting the global flag
:- set_flag(goal_expansion, off).The global flag also controls whether transformations are applied to goals entered at the interactive toplevel prompt.
:- inline(double/2). double(X, Y) :- Y is 2*X. % The predicate sample :- ..., double(A, B), ... % will be compiled as sample :- ..., B is 2*A, ... :- inline(yesno/1). yesno(yes). yesno(no). % The predicate sample :- ..., yesno(X), ... % will be compiled as sample :- ..., (X=yes;X=no), ...