________________________________________________________________________

This file is part of Logtalk <http://logtalk.org/>  

Logtalk is free software. You can redistribute it and/or modify it under
the terms of the FSF GNU General Public License 3  (plus some additional
terms per section 7).        Consult the `LICENSE.txt` file for details.
________________________________________________________________________


% start by loading the example:

| ?- logtalk_load(expansion(loader)).
...


% simple tests of the expand_term/2 and expand_goal/2 built-in methods:


% sending the messages expand_term/2 (expand_goal/2) to an object only
% result in the use of the clauses defined for the term_expansion/2 
% (goal_expansion/2) hook predicate if this predicate is public:

| ?- exp_public::expand_term(8, Term).

Term = eight 
yes

| ?- exp_public::expand_goal(write(Term), EGoal).

EGoal = write_term(Term, [quoted(true)]).
yes


% the clauses for the term_expansion/2 (goal_expansion/2) hook predicate
% will not be used if they are not within the scope of the sender (in this
% case, the pseudo-object "user") as in the following cases:

| ?- exp_protected::expand_term(8, Term).

Term = 8 
yes

| ?- exp_protected::expand_goal(write(Term), EGoal).

EGoal = write(Term).
yes


| ?- exp_private::expand_term(8, Term).

Term = 8 
yes

| ?- exp_private::expand_goal(write(Term), EGoal).

EGoal = write(Term).
yes


% the following queries perform similar tests but with the calls to the
% expand_term/2 (expand_goal/2) built-in method being made from within 
% the prototypes:


| ?- desc_public::test_term_expansion(8, Term).

Term = eight 
yes

| ?- desc_public::test_goal_expansion(write(Term), EGoal).

EGoal = write_term(Term, [quoted(true)])
yes


| ?- desc_protected::test_term_expansion(8, Term).

Term = eight 
yes

| ?- desc_protected::test_goal_expansion(write(Term), EGoal).

EGoal = write_term(Term, [quoted(true)])
yes


| ?- desc_private::test_term_expansion(8, Term).

Term = 8 
yes

| ?- desc_private::test_goal_expansion(write(Term), EGoal).

EGoal = write(Term)
yes


% simple tests of hook objects:

| ?- cooked << (aa, bb, cc).
yes

| ?- cooked << (ha, hb, hc).
yes

| ?- cooked << p.
yes
