Section "expansion"

We only provide shallow term expansion. Shallow term expansion can be defined via the multi-file predicate term_expansion/2, but there is no automatic call of goal_expansion/2 for any subgoals in the directive or clause provided as a term. The Prolog system comes with term expansion for definite clause grammars (DCG).

For the purpose of converting some term back to a more user-friendly form, we further provide deep term portraying. The term portraying can be defined via the multi-file predicate term_portraying/2, but there are currently no predicates print/[1,2]. Instead the predicate is used in formatting and the top-level together with cyclic term compaction.

The following expansion predicates are provided:

term_expansion(X, Y):
This predicate to define custom term expansion rules.
expand_term(X, Y):
The predicate succeeds in Y with the expansion of the term X.
P --> Q: [DCG 7.13.2]
P, R --> Q: [DCG 7.13.2]
The fact is transformed into the DCG clause for the DCG non-terminal P and the DCG body Q. The ternary form allows an additional DCG push back R.
phrase(B, I, O): [DCG 8.1.1]
The predicate succeeds whenever the DCG body B succeeds for the input I and the output O.
term_portraying(X, Y):
The predicate to define custom term portraying rules.
portray_term(X, Y):
The predicate succeeds in Y with the portrayed term X. Knuth Algorithm E with (==)/2 and not showing loops.