Logtalk 2.29.1 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1744 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.28.2
|
||||
Release 2.29.1
|
||||
|
||||
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
|
@@ -1,6 +1,6 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.28.2
|
||||
Release 2.29.1
|
||||
|
||||
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
@@ -59,3 +59,30 @@ exit: sort([4,9],[4,9])
|
||||
Sorted = [1,2,3,4,9] ?
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% call the meta-predicate apply/2 directly:
|
||||
|
||||
| ?- meta::test_this.
|
||||
|
||||
1, meta
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% send an apply/2 message to self:
|
||||
|
||||
| ?- desc::test_self.
|
||||
|
||||
2, desc
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% send an apply/2 message from another object:
|
||||
|
||||
| ?- test::test_obj.
|
||||
|
||||
3, test
|
||||
|
||||
yes
|
||||
|
56
Logtalk/examples/metapredicates/closures.lgt
Normal file
56
Logtalk/examples/metapredicates/closures.lgt
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
/* Logtalk meta-predicates accept not only goals but also closures
|
||||
as meta-arguments as illustrated in this example
|
||||
*/
|
||||
|
||||
|
||||
:- object(meta).
|
||||
|
||||
% the meta_predicate/1 directive below changes the interpretation of meta-calls on apply/2
|
||||
% clauses; the integer argument ("1") implies that the first argument is a closure that will
|
||||
% be used to construct a goal by appending exactly one additional argument
|
||||
|
||||
:- public(apply/2).
|
||||
:- mode(apply(+callable, ?term), zero_or_more).
|
||||
:- meta_predicate(apply(1, *)).
|
||||
|
||||
apply(Closure, Arg) :- % the Logtalk compiler verifies that any closure which is a
|
||||
call(Closure, Arg). % meta-argument is used within a call/N method that honors the
|
||||
% meta-predicate directive (in this case, apply(1, *) => call/2)
|
||||
|
||||
:- public(test_this/0). % simple predicate for testing calls to a local meta-predicate
|
||||
|
||||
test_this :-
|
||||
apply(foo(X), Y),
|
||||
write((X, Y)), nl.
|
||||
|
||||
foo(1, meta).
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
||||
:- object(desc,
|
||||
extends(meta)).
|
||||
|
||||
:- public(test_self/0). % simple predicate for testing calls to a meta-predicate
|
||||
% defined in an ancestor object
|
||||
test_self :-
|
||||
::apply(foo(X), Y),
|
||||
write((X, Y)), nl.
|
||||
|
||||
foo(2, desc).
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
||||
:- object(test).
|
||||
|
||||
:- public(test_obj/0). % simple predicate for testing calls to a meta-predicate
|
||||
% defined in another object
|
||||
test_obj :-
|
||||
meta::apply(foo(X), Y),
|
||||
write((X, Y)), nl.
|
||||
|
||||
foo(3, test).
|
||||
|
||||
:- end_object.
|
@@ -1,13 +1,15 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load(
|
||||
[metapredicates])).
|
||||
logtalk_load([
|
||||
closures,
|
||||
metapredicates])).
|
||||
|
||||
/*
|
||||
If you intend to use the FOP XSL:FO processor for generating PDF documenting
|
||||
files, comment the directive above and uncomment the directive below
|
||||
|
||||
:- initialization(
|
||||
logtalk_load(
|
||||
[metapredicates], [xmlsref(standalone)])).
|
||||
logtalk_load([
|
||||
closures,
|
||||
metapredicates], [xmlsref(standalone)])).
|
||||
*/
|
||||
|
Reference in New Issue
Block a user