Did you know ... Search Documentation:
Pack logtalk -- logtalk-3.77.0/examples/expansion/SCRIPT.txt

This file is part of Logtalk https://logtalk.org/ SPDX-FileCopyrightText: 1998-2023 Paulo Moura <pmoura@logtalk.org> SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

% 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

| ?- piped<<a(key-value). yes

| ?- piped<<b(key-value). yes

| ?- piped<<c(key-value). yes