________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
SPDX-FileCopyrightText: 1998-2024 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(self_vs_super(loader)).
...


% illustrate the differences between sending a message to "self"
% and making a "super" call to call an inherited meta-predicate


% "user" defines a foo/1 predicate:

| ?- foo(X).

X = 1 ? ;
X = 2 ? ;
X = 3
yes


% "super" calls preserve "sender" and therefore the foo/1 predicate
% is called by the meta-predicate in the context of "user":

| ?- proto::meta_super(foo, X).
Execution context for the parent object meta/2 meta-predicate:
  self: proto
  this: parent
  sender: user

X = 1 ? ;
X = 2 ? ;
X = 3
yes


% messages to "self" reset "sender" and therefore the foo/1 predicate
% is called in the context of "proto", hence the existence error:

| ?- proto::meta_self(foo, X).
Execution context for the parent object meta/2 meta-predicate:
  self: proto
  this: parent
  sender: proto

uncaught exception: error(existence_error(procedure,foo/1),logtalk(call(foo(_307)),c(proto,proto,r(user,proto,c(user,user,r(user,proto,[],[])),[]))))
