Logtalk 2.30.1 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1903 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
This folder contains some useful objects, categories, and protocols.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
| ?- meta::succeeds(integer, [1, 2, 3]).
|
||||
|
@@ -2,38 +2,30 @@
|
||||
:- object(after_event_registry,
|
||||
implements(event_registryp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'After events registry predicates.']).
|
||||
|
||||
|
||||
monitors(Monitors) :-
|
||||
findall(Monitor, current_event(after, _, _, _, Monitor), List),
|
||||
{sort(List, Monitors)}.
|
||||
|
||||
|
||||
monitored(Objects) :-
|
||||
findall(Object, current_event(after, Object, _, _, _), List),
|
||||
{sort(List, Objects)}.
|
||||
|
||||
|
||||
monitor(Object, Message, Sender, Monitor) :-
|
||||
current_event(after, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
set_monitor(Object, Message, Sender, Monitor) :-
|
||||
define_events(after, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
del_monitors(Object, Message, Sender, Monitor) :-
|
||||
abolish_events(after, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
del_monitors :-
|
||||
abolish_events(after, _, _, _, _).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,10 +1,10 @@
|
||||
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
The all_loader.lgt file will load all the entities loaded by the other
|
||||
|
@@ -15,14 +15,12 @@ version 2.1 (http://opensource.org/licenses/osl-2.1.php).
|
||||
|
||||
:- category(assignvars).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Nobukuni Kino and Paulo Moura',
|
||||
date is 2005/1/7,
|
||||
comment is 'Assignable variables (supporting logical, backtracable assignement of non-variable terms).']).
|
||||
|
||||
|
||||
:- public(assignable/1).
|
||||
:- mode(assignable(-assignvar), one).
|
||||
:- info(assignable/1, [
|
||||
@@ -56,35 +54,28 @@ version 2.1 (http://opensource.org/licenses/osl-2.1.php).
|
||||
exceptions is [
|
||||
'Variable is not instantiated' - instantiation_error]]).
|
||||
|
||||
|
||||
:-op(100, xfx, <=).
|
||||
:-op(100, xfx, =>).
|
||||
|
||||
|
||||
assignable(Assig) :-
|
||||
nonvar(Assig),
|
||||
self(Self),
|
||||
sender(Sender),
|
||||
throw(error(type_error(variable, Assig), Self::assignable(Assig), Sender)).
|
||||
|
||||
assignable([_| _]).
|
||||
|
||||
|
||||
assignable(Assig, Init) :-
|
||||
nonvar(Assig),
|
||||
self(Self),
|
||||
sender(Sender),
|
||||
throw(error(type_error(variable, Assig), Self::assignable(Assig, Init), Sender)).
|
||||
|
||||
assignable(Assig, Init) :-
|
||||
var(Init),
|
||||
self(Self),
|
||||
sender(Sender),
|
||||
throw(error(instantiation_error, Self::assignable(Assig, Init), Sender)).
|
||||
|
||||
assignable([_, Init| _], Init).
|
||||
|
||||
|
||||
Assig <= Value :-
|
||||
var(Value),
|
||||
self(Self),
|
||||
@@ -97,7 +88,6 @@ version 2.1 (http://opensource.org/licenses/osl-2.1.php).
|
||||
;
|
||||
Tail = [Value| _].
|
||||
|
||||
|
||||
Assig => Value :-
|
||||
var(Assig),
|
||||
self(Self),
|
||||
@@ -110,5 +100,4 @@ version 2.1 (http://opensource.org/licenses/osl-2.1.php).
|
||||
;
|
||||
Current = Value.
|
||||
|
||||
|
||||
:- end_category.
|
||||
|
@@ -2,16 +2,13 @@
|
||||
:- object(atom,
|
||||
extends(atomic)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Atom data type predicates.']).
|
||||
|
||||
|
||||
valid(Atom) :-
|
||||
atom(Atom).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -2,16 +2,13 @@
|
||||
:- object(atomic,
|
||||
extends(term)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Atomic data type predicates.']).
|
||||
|
||||
|
||||
valid(Atomic) :-
|
||||
atomic(Atomic).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,105 +1,75 @@
|
||||
|
||||
:- category(attributes).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Dynamic attributes dictionary.']).
|
||||
|
||||
|
||||
:- public(attribute/2).
|
||||
|
||||
:- mode(attribute(?nonvar, ?nonvar), zero_or_more).
|
||||
|
||||
:- info(attribute/2,
|
||||
[comment is 'Returns, by backtracking, all pairs of atribute-values.',
|
||||
argnames is ['Attribute', 'Value']]).
|
||||
|
||||
|
||||
:- public(attributes/1).
|
||||
|
||||
:- mode(attributes(-list), one).
|
||||
|
||||
:- info(attributes/1,
|
||||
[comment is 'List of all pairs of atribute-values.',
|
||||
argnames is ['Attributes']]).
|
||||
|
||||
|
||||
:- private(attribute_/2).
|
||||
:- dynamic(attribute_/2).
|
||||
|
||||
:- mode(attribute_(?nonvar, ?nonvar), zero_or_more).
|
||||
|
||||
:- info(attribute_/2,
|
||||
[comment is 'Stores attributes values.',
|
||||
argnames is ['Attribute', 'Value']]).
|
||||
|
||||
|
||||
:- public(del_attribute/2).
|
||||
|
||||
:- mode(del_attribute(?nonvar, ?nonvar), zero_or_more).
|
||||
|
||||
:- info(del_attribute/2,
|
||||
[comment is 'Deletes a matching attribute-value pair.',
|
||||
argnames is ['Attribute', 'Value']]).
|
||||
|
||||
|
||||
:- public(del_attributes/2).
|
||||
|
||||
:- mode(del_attributes(@term, @term), one).
|
||||
|
||||
:- info(del_attributes/2,
|
||||
[comment is 'Deletes all matching attribute-value pairs.',
|
||||
argnames is ['Attribute', 'Value']]).
|
||||
|
||||
|
||||
:- public(set_attribute/2).
|
||||
|
||||
:- mode(set_attribute(+nonvar, +nonvar), one).
|
||||
|
||||
:- info(set_attribute/2,
|
||||
[comment is 'Sets an attribute value.',
|
||||
argnames is ['Attribute', 'Value']]).
|
||||
|
||||
|
||||
:- public(set_attributes/1).
|
||||
|
||||
:- mode(set_attributes(+list), one).
|
||||
|
||||
:- info(set_attributes/1,
|
||||
[comment is 'Sets a list of attribute-value pairs.',
|
||||
argnames is ['Attributes']]).
|
||||
|
||||
|
||||
attribute(Attribute, Value) :-
|
||||
::attribute_(Attribute, Value).
|
||||
|
||||
|
||||
attributes(Attributes) :-
|
||||
findall(Attribute, ::attribute_(Attribute, _), Attributes).
|
||||
|
||||
|
||||
del_attribute(Attribute, Value) :-
|
||||
::retract(attribute_(Attribute, Value)).
|
||||
|
||||
|
||||
del_attributes(Attribute, Value) :-
|
||||
::retractall(attribute_(Attribute, Value)).
|
||||
|
||||
|
||||
set_attribute(Attribute, Value) :-
|
||||
::retractall(attribute_(Attribute, _)),
|
||||
::assertz(attribute_(Attribute, Value)).
|
||||
|
||||
|
||||
set_attributes([]).
|
||||
|
||||
set_attributes([Attribute-Value| Attributes]) :-
|
||||
::retractall(attribute_(Attribute, _)),
|
||||
::assertz(attribute_(Attribute, Value)),
|
||||
set_attributes(Attributes).
|
||||
|
||||
|
||||
:- end_category.
|
||||
|
@@ -2,38 +2,30 @@
|
||||
:- object(before_event_registry,
|
||||
implements(event_registryp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Before events registry predicates.']).
|
||||
|
||||
|
||||
monitors(Monitors) :-
|
||||
findall(Monitor, current_event(before, _, _, _, Monitor), List),
|
||||
{sort(List, Monitors)}.
|
||||
|
||||
|
||||
monitored(Objects) :-
|
||||
findall(Object, current_event(before, Object, _, _, _), List),
|
||||
{sort(List, Objects)}.
|
||||
|
||||
|
||||
monitor(Object, Message, Sender, Monitor) :-
|
||||
current_event(before, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
set_monitor(Object, Message, Sender, Monitor) :-
|
||||
define_events(before, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
del_monitors(Object, Message, Sender, Monitor) :-
|
||||
abolish_events(before, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
del_monitors :-
|
||||
abolish_events(before, _, _, _, _).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -3,153 +3,112 @@
|
||||
implements(dictionaryp),
|
||||
extends(compound)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/9/17,
|
||||
comment is 'Dictionary protocol implemented using binary trees.']).
|
||||
|
||||
|
||||
:- private(map/4).
|
||||
:- meta_predicate(map(*, *, *, ::)).
|
||||
|
||||
:- mode(map(+atom, +tree, -tree, -callable), zero_or_one).
|
||||
|
||||
|
||||
as_list(Tree, List) :-
|
||||
as_list(Tree, [], List).
|
||||
|
||||
|
||||
as_list(t, List, List).
|
||||
|
||||
as_list(t(Key, Value, Left, Right), Acc, List) :-
|
||||
as_list(Right, Acc, Acc2),
|
||||
as_list(Left, [Key-Value| Acc2], List).
|
||||
|
||||
|
||||
empty(Tree) :-
|
||||
Tree == t.
|
||||
|
||||
|
||||
insert(Key, Value, t, t(Key, Value, t, t)) :-
|
||||
nonvar(Key).
|
||||
|
||||
insert(Key, Value, t(Key1, Value1, Left1, Right1), t(Key1, Value2, Left2, Right2)) :-
|
||||
compare(Order, Key, Key1),
|
||||
insert(Order, Key, Value, Key1, Value1, Left1, Right1, Value2, Left2, Right2).
|
||||
|
||||
|
||||
insert(=, _, Value, _, _, Left, Right, Value, Left, Right).
|
||||
|
||||
insert(<, Key, Value, _, Value1, Left1, Right, Value1, Left2, Right) :-
|
||||
insert(Key, Value, Left1, Left2).
|
||||
|
||||
insert(>, Key, Value, _, Value1, Left, Right1, Value1, Left, Right2) :-
|
||||
insert(Key, Value, Right1, Right2).
|
||||
|
||||
|
||||
insert_all([], Tree, Tree).
|
||||
|
||||
insert_all([Key-Value| Rest], Old, New) :-
|
||||
insert(Key, Value, Old, Aux),
|
||||
insert_all(Rest, Aux, New).
|
||||
|
||||
|
||||
lookup(Key, Value, Tree) :-
|
||||
var(Key) ->
|
||||
( var(Key) ->
|
||||
lookup_var(Key, Value, Tree)
|
||||
;
|
||||
lookup_nonvar(Key, Value, Tree).
|
||||
|
||||
; lookup_nonvar(Key, Value, Tree)
|
||||
).
|
||||
|
||||
lookup_nonvar(Key, Value, t(Key1, Value1, Left1, Right1)) :-
|
||||
compare(Order, Key, Key1),
|
||||
lookup_nonvar(Order, Key, Value, Value1, Left1, Right1).
|
||||
|
||||
|
||||
lookup_nonvar(=, _, Value, Value, _, _).
|
||||
|
||||
lookup_nonvar(<, Key, Value, _, Left, _) :-
|
||||
lookup_nonvar(Key, Value, Left).
|
||||
|
||||
lookup_nonvar(<, Key, Value, _, _, Right) :-
|
||||
lookup_nonvar(Key, Value, Right).
|
||||
|
||||
|
||||
lookup_var(Key, Value, t(_, _, Left, _)) :-
|
||||
lookup_var(Key, Value, Left).
|
||||
|
||||
lookup_var(Key, Value, t(Key, Value,_,_)).
|
||||
|
||||
lookup_var(Key, Value, t(_, _, _, Right)) :-
|
||||
lookup_var(Key, Value, Right).
|
||||
|
||||
|
||||
keys(Tree, Keys) :-
|
||||
keys(Tree, [], Keys).
|
||||
|
||||
|
||||
keys(t, Keys, Keys).
|
||||
|
||||
keys(t(Key, _, Left, Right), Acc, Keys) :-
|
||||
keys(Right, Acc, Acc2),
|
||||
keys(Left, [Key| Acc2], Keys).
|
||||
|
||||
|
||||
delete(t, _, _, t).
|
||||
|
||||
delete(t(Key1, Value1, Left1, Right1), Key, Value, Out) :-
|
||||
compare(Order, Key, Key1),
|
||||
delete(Order, Key1, Value1, Left1, Right1, Key, Value, Out).
|
||||
|
||||
|
||||
delete(=, Key1, Value1, Left1, Right1, Key1, Value1, Out) :-
|
||||
join(Left1, Right1, Out).
|
||||
|
||||
delete(<, Key1, Value1, Left1, Right1, Key, Value, t(Key1, Value1, Left2, Right1)) :-
|
||||
delete(Left1, Key, Value, Left2).
|
||||
|
||||
delete(>, Key1, Value1, Left1, Right1, Key, Value, t(Key1, Value1, Left1, Right2)) :-
|
||||
delete(Right1, Key, Value, Right2).
|
||||
|
||||
|
||||
join(t, Right, Right) :-
|
||||
!.
|
||||
|
||||
join(Left, t, Left) :-
|
||||
!.
|
||||
|
||||
join(t(Key, Value, Left, Right), Tree, t(Key, Value, Left, Right2)) :-
|
||||
join(Right, Tree, Right2).
|
||||
|
||||
|
||||
map(Pred, Old, New) :-
|
||||
map(Pred, Old, New, _).
|
||||
|
||||
|
||||
map(Pred, t(Key1, Value1, Left1, Right1), t(Key2, Value2, Left2, Right2), Goal) :-
|
||||
Goal =.. [Pred, Key1-Value1, Key2-Value2],
|
||||
once(Goal),
|
||||
map(Pred, Left1, Left2, _),
|
||||
map(Pred, Right1, Right2, _).
|
||||
|
||||
map(_, t, t, _).
|
||||
|
||||
|
||||
new(t).
|
||||
|
||||
|
||||
size(Dictionary, Size) :-
|
||||
size(Dictionary, 0, Size).
|
||||
|
||||
|
||||
size(t, Size, Size).
|
||||
|
||||
size(t(_, _, Left, Right), Acc, Size) :-
|
||||
size(Left, Acc, Acc2),
|
||||
Acc3 is Acc2 + 1,
|
||||
size(Right, Acc3, Size).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -2,16 +2,16 @@
|
||||
:- object(callable,
|
||||
extends(term)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
date is 2007/4/29,
|
||||
comment is 'Callable term type predicates.']).
|
||||
|
||||
|
||||
valid(Callable) :-
|
||||
once((atom(Callable); compound(Callable))).
|
||||
|
||||
( atom(Callable) ->
|
||||
true
|
||||
; compound(Callable)
|
||||
).
|
||||
|
||||
:- end_object.
|
||||
|
@@ -3,87 +3,68 @@
|
||||
implements(characterp),
|
||||
extends(atom)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Character predicates.']).
|
||||
|
||||
|
||||
is_alpha('_').
|
||||
|
||||
is_alpha(Char) :-
|
||||
is_letter(Char).
|
||||
|
||||
|
||||
is_letter(Char) :-
|
||||
is_lower_case(Char).
|
||||
|
||||
is_letter(Char) :-
|
||||
is_upper_case(Char).
|
||||
|
||||
|
||||
is_alphanumeric(Char) :-
|
||||
is_alpha(Char).
|
||||
|
||||
is_alphanumeric(Char) :-
|
||||
is_dec_digit(Char).
|
||||
|
||||
|
||||
is_bin_digit(0).
|
||||
is_bin_digit(1).
|
||||
|
||||
|
||||
is_octal_digit(Digit) :-
|
||||
Digit @>= 0,
|
||||
Digit @=< 7.
|
||||
|
||||
|
||||
is_dec_digit(Digit) :-
|
||||
Digit @>= 0,
|
||||
Digit @=< 9.
|
||||
|
||||
|
||||
is_hex_digit(Digit) :-
|
||||
Digit @>= 0,
|
||||
Digit @=< 9.
|
||||
|
||||
is_hex_digit(Digit) :-
|
||||
Digit @>= 'A',
|
||||
Digit @=< 'F'.
|
||||
|
||||
is_hex_digit(Digit) :-
|
||||
Digit @>= a,
|
||||
Digit @=< f.
|
||||
|
||||
|
||||
is_lower_case(Char) :-
|
||||
Char @>= a,
|
||||
Char @=< z.
|
||||
|
||||
|
||||
is_upper_case(Char) :-
|
||||
Char @>= 'A',
|
||||
Char @=< 'Z'.
|
||||
|
||||
|
||||
is_vowel(a).
|
||||
is_vowel(e).
|
||||
is_vowel(i).
|
||||
is_vowel(o).
|
||||
is_vowel(u).
|
||||
|
||||
is_vowel('A').
|
||||
is_vowel('E').
|
||||
is_vowel('I').
|
||||
is_vowel('O').
|
||||
is_vowel('U').
|
||||
|
||||
|
||||
is_layout(' ').
|
||||
|
||||
|
||||
lower_upper(a, 'A').
|
||||
lower_upper(b, 'B').
|
||||
lower_upper(c, 'C').
|
||||
@@ -110,15 +91,12 @@
|
||||
lower_upper(x, 'X').
|
||||
lower_upper(y, 'Y').
|
||||
lower_upper(z, 'Z').
|
||||
|
||||
lower_upper(Char, Char) :-
|
||||
\+ (Char @>= a, Char @=< z),
|
||||
\+ (Char @>= 'A', Char @=< 'Z').
|
||||
|
||||
|
||||
valid(Character) :-
|
||||
atom(Character),
|
||||
atom_length(Character, 1).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,122 +1,84 @@
|
||||
|
||||
:- protocol(characterp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Character protocol.']).
|
||||
|
||||
|
||||
:- public(is_alphanumeric/1).
|
||||
|
||||
:- mode(is_alphanumeric(+char), zero_or_one).
|
||||
|
||||
:- info(is_alphanumeric/1, [
|
||||
comment is 'True if the argument is an alphanumeric character.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_alpha/1).
|
||||
|
||||
:- mode(is_alpha(+char), zero_or_one).
|
||||
|
||||
:- info(is_alpha/1, [
|
||||
comment is 'True if the argument is a letter or an underscore.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_letter/1).
|
||||
|
||||
:- mode(is_letter(+char), zero_or_one).
|
||||
|
||||
:- info(is_letter/1, [
|
||||
comment is 'True if the argument is a letter.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_bin_digit/1).
|
||||
|
||||
:- mode(is_bin_digit(+char), zero_or_one).
|
||||
|
||||
:- info(is_bin_digit/1, [
|
||||
comment is 'True if the argument is a binary digit.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_octal_digit/1).
|
||||
|
||||
:- mode(is_octal_digit(+char), zero_or_one).
|
||||
|
||||
:- info(is_octal_digit/1, [
|
||||
comment is 'True if the argument is an octal digit.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_dec_digit/1).
|
||||
|
||||
:- mode(is_dec_digit(+char), zero_or_one).
|
||||
|
||||
:- info(is_dec_digit/1, [
|
||||
comment is 'True if the argument is a decimal digit.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_hex_digit/1).
|
||||
|
||||
:- mode(is_hex_digit(+char), zero_or_one).
|
||||
|
||||
:- info(is_hex_digit/1, [
|
||||
comment is 'True if the argument is an hexadecimal digit.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_lower_case/1).
|
||||
|
||||
:- mode(is_lower_case(+char), zero_or_one).
|
||||
|
||||
:- info(is_lower_case/1, [
|
||||
comment is 'True if the argument is a lower case letter.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_upper_case/1).
|
||||
|
||||
:- mode(is_upper_case(+char), zero_or_one).
|
||||
|
||||
:- info(is_upper_case/1, [
|
||||
comment is 'True if the argument is a upper case letter.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_vowel/1).
|
||||
|
||||
:- mode(is_vowel(+char), zero_or_one).
|
||||
|
||||
:- info(is_vowel/1, [
|
||||
comment is 'True if the argument is a vowel.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(is_layout/1).
|
||||
|
||||
:- mode(is_layout(+char), zero_or_one).
|
||||
|
||||
:- info(is_layout/1, [
|
||||
comment is 'True if the argument is a layout character.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(lower_upper/2).
|
||||
|
||||
:- mode(lower_upper(?char, ?char), zero_or_more).
|
||||
:- mode(lower_upper(+char, ?char), zero_or_one).
|
||||
:- mode(lower_upper(?char, +char), zero_or_one).
|
||||
|
||||
:- info(lower_upper/2, [
|
||||
comment is 'Converts between lower and upper case letters.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,69 +2,56 @@
|
||||
:- category(class_hierarchy,
|
||||
implements(class_hierarchyp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/2/20,
|
||||
comment is 'Class hierarchy predicates.']).
|
||||
|
||||
|
||||
class(Class) :-
|
||||
self(Self),
|
||||
instantiates_class(Self, Class).
|
||||
|
||||
|
||||
classes(Classes) :-
|
||||
self(Self),
|
||||
findall(Class, instantiates_class(Self, Class), Classes).
|
||||
|
||||
|
||||
ancestor(Ancestor) :-
|
||||
self(Self),
|
||||
ancestor(Self, Ancestor).
|
||||
|
||||
|
||||
ancestor(Self, Ancestor) :-
|
||||
instantiates_class(Self, Ancestor).
|
||||
|
||||
ancestor(Self, Ancestor) :-
|
||||
instantiates_class(Self, Class),
|
||||
superclass(Class, Ancestor).
|
||||
|
||||
|
||||
ancestors(Ancestors) :-
|
||||
self(Self),
|
||||
findall(Ancestor, ancestor(Self, Ancestor), Ancestors).
|
||||
|
||||
|
||||
instance(Instance) :-
|
||||
self(Self),
|
||||
instantiates_class(Instance, Self).
|
||||
|
||||
|
||||
instances(Instances) :-
|
||||
self(Self),
|
||||
findall(Instance, instantiates_class(Instance, Self), Instances).
|
||||
|
||||
|
||||
subclass(Subclass) :-
|
||||
self(Self),
|
||||
specializes_class(Subclass, Self).
|
||||
|
||||
|
||||
subclasses(Subclasses) :-
|
||||
self(Self),
|
||||
findall(Subclass, specializes_class(Subclass, Self), Subclasses).
|
||||
|
||||
|
||||
superclass(Superclass) :-
|
||||
self(Self),
|
||||
superclass(Self, Superclass).
|
||||
|
||||
superclass(Self, Superclass) :-
|
||||
specializes_class(Self, Superclass).
|
||||
|
||||
superclass(Self, Superclass) :-
|
||||
specializes_class(Self, Class),
|
||||
superclass(Class, Superclass).
|
||||
@@ -73,27 +60,22 @@
|
||||
self(Self),
|
||||
findall(Superclass, specializes_class(Self, Superclass), Superclasses).
|
||||
|
||||
|
||||
leaf(Leaf) :-
|
||||
self(Self),
|
||||
leaf(Self, Leaf).
|
||||
|
||||
|
||||
leaf(Self, Leaf) :-
|
||||
instantiates_class(Leaf, Self),
|
||||
\+ instantiates_class(_, Leaf),
|
||||
\+ specializes_class(_, Leaf).
|
||||
|
||||
leaf(Self, Leaf) :-
|
||||
specializes_class(Leaf, Self),
|
||||
\+ instantiates_class(_, Leaf),
|
||||
\+ specializes_class(_, Leaf).
|
||||
|
||||
leaf(Self, Leaf) :-
|
||||
specializes_class(Subclass, Self),
|
||||
leaf(Subclass, Leaf).
|
||||
|
||||
|
||||
leaves(Leaves) :-
|
||||
self(Self),
|
||||
( setof(Leaf, leaf(Self, Leaf), Leaves) ->
|
||||
@@ -101,21 +83,17 @@
|
||||
; Leaves = []
|
||||
).
|
||||
|
||||
|
||||
leaf_instance(Leaf) :-
|
||||
self(Self),
|
||||
leaf_instance(Self, Leaf).
|
||||
|
||||
|
||||
leaf_instance(Self, Leaf) :-
|
||||
instantiates_class(Leaf, Self),
|
||||
\+ instantiates_class(_, Leaf).
|
||||
|
||||
leaf_instance(Self, Leaf) :-
|
||||
specializes_class(Subclass, Self),
|
||||
leaf_instance(Subclass, Leaf).
|
||||
|
||||
|
||||
leaf_instances(Leaves) :-
|
||||
self(Self),
|
||||
( setof(Leaf, leaf_instance(Self, Leaf), Leaves) ->
|
||||
@@ -123,7 +101,6 @@
|
||||
; Leaves = []
|
||||
).
|
||||
|
||||
|
||||
leaf_class(Leaf) :-
|
||||
self(Self),
|
||||
leaf_class(Self, Leaf).
|
||||
@@ -131,7 +108,6 @@
|
||||
leaf_class(Self, Leaf) :-
|
||||
specializes_class(Leaf, Self),
|
||||
\+ specializes_class(_, Leaf).
|
||||
|
||||
leaf_class(Self, Leaf) :-
|
||||
specializes_class(Subclass, Self),
|
||||
leaf_class(Subclass, Leaf).
|
||||
@@ -143,24 +119,19 @@
|
||||
; Leaves = []
|
||||
).
|
||||
|
||||
|
||||
descendant(Descendant) :-
|
||||
self(Self),
|
||||
descendant(Self, Descendant).
|
||||
|
||||
|
||||
descendant(Self, Descendant) :-
|
||||
instantiates_class(Descendant, Self).
|
||||
|
||||
descendant(Self, Descendant) :-
|
||||
specializes_class(Descendant, Self),
|
||||
\+ instantiates_class(Descendant, Self).
|
||||
|
||||
descendant(Self, Descendant) :-
|
||||
specializes_class(Subclass, Self),
|
||||
descendant(Subclass, Descendant).
|
||||
|
||||
|
||||
descendants(Descendants) :-
|
||||
self(Self),
|
||||
( setof(Descendant, descendant(Self, Descendant), Descendants) ->
|
||||
@@ -168,20 +139,16 @@
|
||||
; Descendants = []
|
||||
).
|
||||
|
||||
|
||||
descendant_class(Descendant) :-
|
||||
self(Self),
|
||||
descendant_class(Self, Descendant).
|
||||
|
||||
|
||||
descendant_class(Self, Descendant) :-
|
||||
specializes_class(Descendant, Self).
|
||||
|
||||
descendant_class(Self, Descendant) :-
|
||||
specializes_class(Subclass, Self),
|
||||
descendant_class(Subclass, Descendant).
|
||||
|
||||
|
||||
descendant_classes(Descendants) :-
|
||||
self(Self),
|
||||
( setof(Descendant, descendant_class(Self, Descendant), Descendants) ->
|
||||
@@ -189,20 +156,16 @@
|
||||
; Descendants = []
|
||||
).
|
||||
|
||||
|
||||
descendant_instance(Descendant) :-
|
||||
self(Self),
|
||||
descendant_instance(Self, Descendant).
|
||||
|
||||
|
||||
descendant_instance(Self, Descendant) :-
|
||||
instantiates_class(Descendant, Self).
|
||||
|
||||
descendant_instance(Self, Descendant) :-
|
||||
specializes_class(Subclass, Self),
|
||||
descendant_instance(Subclass, Descendant).
|
||||
|
||||
|
||||
descendant_instances(Descendants) :-
|
||||
self(Self),
|
||||
( setof(Descendant, descendant_instance(Self, Descendant), Descendants) ->
|
||||
@@ -210,5 +173,4 @@
|
||||
; Descendants = []
|
||||
).
|
||||
|
||||
|
||||
:- end_category.
|
||||
|
@@ -2,156 +2,106 @@
|
||||
:- protocol(class_hierarchyp,
|
||||
extends(hierarchyp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Class hierarchy protocol.']).
|
||||
|
||||
|
||||
:- public(class/1).
|
||||
|
||||
:- mode(class(?object), zero_or_more).
|
||||
|
||||
:- info(class/1, [
|
||||
comment is 'Returns, by backtracking, all object classes.',
|
||||
argnames is ['Class']]).
|
||||
|
||||
|
||||
:- public(classes/1).
|
||||
|
||||
:- mode(classes(-list), one).
|
||||
|
||||
:- info(classes/1, [
|
||||
comment is 'List of all object classes.',
|
||||
argnames is ['Classes']]).
|
||||
|
||||
|
||||
:- public(instance/1).
|
||||
|
||||
:- mode(instance(?object), zero_or_more).
|
||||
|
||||
:- info(instance/1, [
|
||||
comment is 'Returns, by backtracking, all class instances.',
|
||||
argnames is ['Instance']]).
|
||||
|
||||
|
||||
:- public(instances/1).
|
||||
|
||||
:- mode(instances(-list), one).
|
||||
|
||||
:- info(instances/1, [
|
||||
comment is 'List of all class instances.',
|
||||
argnames is ['Instances']]).
|
||||
|
||||
|
||||
:- public(subclass/1).
|
||||
|
||||
:- mode(subclass(?object), zero_or_more).
|
||||
|
||||
:- info(subclass/1, [
|
||||
comment is 'Returns, by backtracking, all class subclasses.',
|
||||
argnames is ['Subclass']]).
|
||||
|
||||
|
||||
:- public(subclasses/1).
|
||||
|
||||
:- mode(subclasses(-list), one).
|
||||
|
||||
:- info(subclasses/1, [
|
||||
comment is 'List of all class subclasses.',
|
||||
argnames is ['Subclasses']]).
|
||||
|
||||
|
||||
:- public(superclass/1).
|
||||
|
||||
:- mode(superclass(?object), zero_or_more).
|
||||
|
||||
:- info(superclass/1, [
|
||||
comment is 'Returns, by backtracking, all class superclasses.',
|
||||
argnames is ['Superclass']]).
|
||||
|
||||
|
||||
:- public(superclasses/1).
|
||||
|
||||
:- mode(superclasses(-list), one).
|
||||
|
||||
:- info(superclasses/1, [
|
||||
comment is 'List of all class superclasses.',
|
||||
argnames is ['Superclasses']]).
|
||||
|
||||
|
||||
:- public(leaf_instance/1).
|
||||
|
||||
:- mode(leaf_instance(?object), zero_or_more).
|
||||
|
||||
:- info(leaf_instance/1, [
|
||||
comment is 'Returns, by backtracking, all class leaf instances.',
|
||||
argnames is ['Leaf']]).
|
||||
|
||||
|
||||
:- public(leaf_instances/1).
|
||||
|
||||
:- mode(leaf_instances(-list), one).
|
||||
|
||||
:- info(leaf_instances/1, [
|
||||
comment is 'List of all class leaf instances.',
|
||||
argnames is ['Leaves']]).
|
||||
|
||||
|
||||
:- public(leaf_class/1).
|
||||
|
||||
:- mode(leaf_class(?object), zero_or_more).
|
||||
|
||||
:- info(leaf_class/1, [
|
||||
comment is 'Returns, by backtracking, all class leaf subclasses.',
|
||||
argnames is ['Leaf']]).
|
||||
|
||||
|
||||
:- public(leaf_classes/1).
|
||||
|
||||
:- mode(leaf_classes(-list), one).
|
||||
|
||||
:- info(leaf_classes/1, [
|
||||
comment is 'List of all class leaf leaf subclasses.',
|
||||
argnames is ['Leaves']]).
|
||||
|
||||
|
||||
:- public(descendant_instance/1).
|
||||
|
||||
:- mode(descendant_instance(?object), zero_or_more).
|
||||
|
||||
:- info(descendant_instance/1, [
|
||||
comment is 'Returns, by backtracking, all class descendant instances.',
|
||||
argnames is ['Descendant']]).
|
||||
|
||||
|
||||
:- public(descendant_instances/1).
|
||||
|
||||
:- mode(descendant_instances(-list), one).
|
||||
|
||||
:- info(descendant_instances/1, [
|
||||
comment is 'List of all class descendant instances.',
|
||||
argnames is ['Descendants']]).
|
||||
|
||||
|
||||
:- public(descendant_class/1).
|
||||
|
||||
:- mode(descendant_class(?object), zero_or_more).
|
||||
|
||||
:- info(descendant_class/1, [
|
||||
comment is 'Returns, by backtracking, all class descendant subclasses.',
|
||||
argnames is ['Descendant']]).
|
||||
|
||||
|
||||
:- public(descendant_classes/1).
|
||||
|
||||
:- mode(descendant_classes(-list), one).
|
||||
|
||||
:- info(descendant_classes/1, [
|
||||
comment is 'List of all class descendant subclasses.',
|
||||
argnames is ['Descendants']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,66 +1,46 @@
|
||||
|
||||
:- protocol(comparingp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Comparing protocol using overloading of standard operators.']).
|
||||
|
||||
|
||||
:- public((<)/2).
|
||||
|
||||
:- mode(<(+term, +term), zero_or_one).
|
||||
|
||||
:- info((<)/2, [
|
||||
comment is 'True if Term1 is less than Term2.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- public((=<)/2).
|
||||
|
||||
:- mode(=<(+term, +term), zero_or_one).
|
||||
|
||||
:- info((=<)/2, [
|
||||
comment is 'True if Term1 is less or equal than Term2.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- public((>)/2).
|
||||
|
||||
:- mode(>(+term, +term), zero_or_one).
|
||||
|
||||
:- info((>)/2, [
|
||||
comment is 'True if Term1 is greater than Term2.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- public((>=)/2).
|
||||
|
||||
:- mode(>=(+term, +term), zero_or_one).
|
||||
|
||||
:- info((>=)/2, [
|
||||
comment is 'True if Term1 is equal or grater than Term2.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- public((=:=)/2).
|
||||
|
||||
:- mode(=:=(+term, +term), zero_or_one).
|
||||
|
||||
:- info((=:=)/2, [
|
||||
comment is 'True if Term1 is equal to Term2.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- public((=\=)/2).
|
||||
|
||||
:- mode(=\=(+term, +term), zero_or_one).
|
||||
|
||||
:- info((=\=)/2, [
|
||||
comment is 'True if Term1 is not equal to Term2.',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,16 +2,13 @@
|
||||
:- object(compound,
|
||||
extends(term)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Compound data type.']).
|
||||
|
||||
|
||||
valid(Compound) :-
|
||||
compound(Compound).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -2,25 +2,21 @@
|
||||
:- object(date,
|
||||
implements(datep)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/3/7,
|
||||
comment is 'Date predicates.']).
|
||||
|
||||
|
||||
today(Year, Month, Day) :-
|
||||
{'$lgt_current_date'(Year, Month, Day)}.
|
||||
|
||||
|
||||
leap_year(Year) :-
|
||||
( 0 =:= mod(Year, 4), 0 =\= mod(Year, 100) ->
|
||||
true
|
||||
; 0 =:= mod(Year, 400)
|
||||
).
|
||||
|
||||
|
||||
name_of_day(1, 'Sunday', 'Sun').
|
||||
name_of_day(2, 'Monday', 'Mon').
|
||||
name_of_day(3, 'Tuesday', 'Tue').
|
||||
@@ -29,7 +25,6 @@
|
||||
name_of_day(6, 'Friday', 'Fri').
|
||||
name_of_day(7, 'Saturday', 'Sat').
|
||||
|
||||
|
||||
name_of_month( 1, 'January', 'Jan').
|
||||
name_of_month( 2, 'February', 'Feb').
|
||||
name_of_month( 3, 'March', 'Mar').
|
||||
@@ -43,7 +38,6 @@
|
||||
name_of_month(11, 'November', 'Nov').
|
||||
name_of_month(12, 'December', 'Dec').
|
||||
|
||||
|
||||
days_in_month( 1, _, 31).
|
||||
days_in_month( 2, Year, Days) :-
|
||||
leap_year(Year) -> Days = 29; Days = 28.
|
||||
@@ -58,7 +52,6 @@
|
||||
days_in_month(11, _, 30).
|
||||
days_in_month(12, _, 31).
|
||||
|
||||
|
||||
valid(Year, Month, Day) :-
|
||||
integer(Year),
|
||||
integer(Month), Month >= 1, Month =< 12,
|
||||
@@ -66,5 +59,4 @@
|
||||
days_in_month(Month, Year, Days),
|
||||
Day >= 1, Day =< Days.
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,66 +1,46 @@
|
||||
|
||||
:- protocol(datep).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2005/3/17,
|
||||
comment is 'Date protocol.']).
|
||||
|
||||
|
||||
:- public(today/3).
|
||||
|
||||
:- mode(today(-integer, -integer, -integer), one).
|
||||
|
||||
:- info(today/3, [
|
||||
comment is 'Returns current date.',
|
||||
argnames is ['Year', 'Month', 'Day']]).
|
||||
|
||||
|
||||
:- public(leap_year/1).
|
||||
|
||||
:- mode(leap_year(+integer), zero_or_one).
|
||||
|
||||
:- info(leap_year/1,
|
||||
[comment is 'True if the argument is a leap year.',
|
||||
argnames is ['Year']]).
|
||||
|
||||
|
||||
:- public(name_of_day/3).
|
||||
|
||||
:- mode(name_of_day(?integer, ?atom, ?atom), zero_or_more).
|
||||
|
||||
:- info(name_of_day/3, [
|
||||
comment is 'Name and short name of day.',
|
||||
argnames is ['Index', 'Name', 'Short']]).
|
||||
|
||||
|
||||
:- public(name_of_month/3).
|
||||
|
||||
:- mode(name_of_month(?integer, ?atom, ?atom), zero_or_more).
|
||||
|
||||
:- info(name_of_month/3, [
|
||||
comment is 'Name and short name of month.',
|
||||
argnames is ['Index', 'Name', 'Short']]).
|
||||
|
||||
|
||||
:- public(days_in_month/3).
|
||||
|
||||
:- mode(days_in_month(?integer, +integer, ?integer), zero_or_more).
|
||||
|
||||
:- info(days_in_month/3, [
|
||||
comment is 'Number of days in a month.',
|
||||
argnames is ['Month', 'Year', 'Days']]).
|
||||
|
||||
|
||||
:- public(valid/3).
|
||||
|
||||
:- mode(valid(@integer, @integer, @integer), zero_or_one).
|
||||
|
||||
:- info(valid/3, [
|
||||
comment is 'True if the arguments represent a valid date.',
|
||||
argnames is ['Year', 'Month', 'Day']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this group load the dates_loader.lgt utility
|
||||
|
@@ -1,5 +1,3 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([
|
||||
datep, date,
|
||||
timep, time])).
|
||||
logtalk_load([datep, date, timep, time], [reload(skip)])).
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this group load the debugging_loader.lgt utility
|
||||
|
@@ -1,3 +1,3 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([event_dbgp, event_dbg], [events(on)])).
|
||||
logtalk_load([event_dbgp, event_dbg], [events(on), reload(skip)])).
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this group load the dependents_loader.lgt
|
||||
|
@@ -1,3 +1,3 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([observer, subject])).
|
||||
logtalk_load([observer, subject], [reload(skip)])).
|
||||
|
@@ -1,103 +1,71 @@
|
||||
|
||||
:- protocol(dictionaryp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Dictionary protocol.']).
|
||||
|
||||
|
||||
:- public(as_dictionary/2).
|
||||
|
||||
:- mode(as_dictionary(@list, -dictionary), one).
|
||||
|
||||
:- info(as_dictionary/2, [
|
||||
comment is 'Converts a list of key-value pairs to a dictionary.',
|
||||
argnames is ['List', 'Dictionary']]).
|
||||
|
||||
|
||||
:- public(as_list/2).
|
||||
|
||||
:- mode(as_list(@dictionary, -list), one).
|
||||
|
||||
:- info(as_list/2, [
|
||||
comment is 'Converts a dictionary to a list of key-value pairs.',
|
||||
argnames is ['Dictionary', 'List']]).
|
||||
|
||||
|
||||
:- public(delete/4).
|
||||
|
||||
:- mode(delete(+dictionary, @ground, ?term, -dictionary), zero_or_one).
|
||||
|
||||
:- info(delete/4, [
|
||||
comment is 'Deletes a matching Key-Value pair from a dictionary, returning the updated dictionary.',
|
||||
argnames is ['Dictionary_in', 'Key', 'Value', 'Dictionary_out']]).
|
||||
|
||||
|
||||
:- public(empty/1).
|
||||
|
||||
:- mode(empty(@dictionary), zero_or_one).
|
||||
|
||||
:- info(empty/1, [
|
||||
comment is 'True if the dictionary is empty.',
|
||||
argnames is ['Dictionary']]).
|
||||
|
||||
|
||||
:- public(insert/4).
|
||||
|
||||
:- mode(insert(+ground, @term, +dictionary, -dictionary), one).
|
||||
|
||||
:- info(insert/4, [
|
||||
comment is 'Inserts a Key-Value pair into a dictionary, returning the updated dictionary.',
|
||||
argnames is ['Key', 'Value', 'Dictionary_in', 'Dictionary_out']]).
|
||||
|
||||
|
||||
:- public(insert_all/3).
|
||||
|
||||
:- mode(insert_all(@list, +dictionary, -dictionary), one).
|
||||
|
||||
:- info(insert_all/3, [
|
||||
comment is 'Inserts a list of Key-Value pairs into a dictionary, returning the updated dictionary.',
|
||||
argnames is ['List', 'Dictionary_in', 'Dictionary_out']]).
|
||||
|
||||
|
||||
:- public(lookup/3).
|
||||
|
||||
:- mode(lookup(+ground, ?term, @dictionary), zero_or_one).
|
||||
:- mode(lookup(-ground, ?term, @dictionary), zero_or_more).
|
||||
|
||||
:- info(lookup/3, [
|
||||
comment is 'Get a matching Key-Value pair from a dictionary.',
|
||||
argnames is ['Key', 'Value', 'Dictionary']]).
|
||||
|
||||
|
||||
:- public(keys/2).
|
||||
|
||||
:- mode(keys(@dictionary, -list), one).
|
||||
|
||||
:- info(keys/2, [
|
||||
comment is 'Returns a list with all dictionary keys.',
|
||||
argnames is ['Dictionary', 'List']]).
|
||||
|
||||
|
||||
:- public(map/3).
|
||||
|
||||
:- mode(map(+functor, +dictionary, -dictionary), zero_or_one).
|
||||
|
||||
:- info(map/3, [
|
||||
comment is 'Maps a binary predicate over each dictionary key-value pair returning a new pair.',
|
||||
argnames is ['Functor', 'In', 'Out']]).
|
||||
|
||||
|
||||
:- public(size/2).
|
||||
|
||||
:- mode(size(@dictionary, ?integer), zero_or_one).
|
||||
|
||||
:- info(size/2, [
|
||||
comment is 'Number of dictionary entries.',
|
||||
argnames is ['Dictionary', 'Size']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -3,28 +3,22 @@
|
||||
implements(listp),
|
||||
extends(compound)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2004/5/9,
|
||||
comment is 'Difference list predicates.']).
|
||||
|
||||
|
||||
:- public(as_list/2).
|
||||
|
||||
:- mode(as_list(+list, -list), one).
|
||||
|
||||
:- info(as_list/2,
|
||||
[comment is 'Converts a difference list to a normal list.',
|
||||
argnames is ['Diffist', 'List']]).
|
||||
|
||||
|
||||
append(List1-Back1, Back1-Back2, List1-Back2) :-
|
||||
nonvar(List1),
|
||||
nonvar(Back1),
|
||||
!.
|
||||
|
||||
append(Prefix, Suffix, List) :-
|
||||
length(List, Length),
|
||||
prefix(Prefix, List),
|
||||
@@ -33,187 +27,153 @@
|
||||
length(Suffix, SLength),
|
||||
suffix(Suffix, List).
|
||||
|
||||
|
||||
as_list(List-Back, Out) :-
|
||||
List == Back ->
|
||||
( List == Back ->
|
||||
Out = []
|
||||
;
|
||||
Out = [Head| Tail],
|
||||
; Out = [Head| Tail],
|
||||
List = [Head| Rest],
|
||||
as_list(Rest-Back, Tail).
|
||||
|
||||
as_list(Rest-Back, Tail)
|
||||
).
|
||||
|
||||
delete(List-Back, Element, Remaining) :-
|
||||
List == Back ->
|
||||
( List == Back ->
|
||||
unify_with_occurs_check(Remaining, Back-Back)
|
||||
;
|
||||
List \== Back,
|
||||
; List \== Back,
|
||||
List = [Head| Tail],
|
||||
(Head == Element ->
|
||||
( Head == Element ->
|
||||
delete(Tail-Back, Element, Remaining)
|
||||
;
|
||||
Remaining = [Head| Tail2],
|
||||
delete(Tail-Back, Element, Tail2-Back)).
|
||||
|
||||
|
||||
; Remaining = [Head| Tail2],
|
||||
delete(Tail-Back, Element, Tail2-Back)
|
||||
)
|
||||
).
|
||||
|
||||
delete_matches(List-Back, Element, Remaining) :-
|
||||
List == Back ->
|
||||
( List == Back ->
|
||||
unify_with_occurs_check(Remaining, Back-Back)
|
||||
;
|
||||
List \== Back,
|
||||
; List \== Back,
|
||||
List = [Head| Tail],
|
||||
(\+ \+ Head = Element ->
|
||||
( \+ \+ Head = Element ->
|
||||
delete_matches(Tail-Back, Element, Remaining)
|
||||
;
|
||||
Remaining = [Head| Tail2],
|
||||
delete_matches(Tail-Back, Element, Tail2-Back)).
|
||||
|
||||
; Remaining = [Head| Tail2],
|
||||
delete_matches(Tail-Back, Element, Tail2-Back)
|
||||
)
|
||||
).
|
||||
|
||||
empty(List-Back) :-
|
||||
List == Back.
|
||||
|
||||
|
||||
flatten(List-Back, Flatted-Back) :-
|
||||
flatten(List-Back, Back-Back, Flatted-Back).
|
||||
|
||||
|
||||
flatten(Var, Tail-Back, [Var| Tail]-Back) :-
|
||||
var(Var),
|
||||
!.
|
||||
|
||||
flatten(List-Back, Flatted, Flatted) :-
|
||||
List == Back,
|
||||
!.
|
||||
|
||||
flatten(List-Back, Acc, Flatted) :-
|
||||
!,
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
flatten(Tail-Back, Acc, Acc2),
|
||||
flatten(Head, Acc2, Flatted).
|
||||
|
||||
flatten(Head, Tail-Back, [Head| Tail]-Back).
|
||||
|
||||
|
||||
keysort(Difflist, Sorted) :-
|
||||
as_list(Difflist, List),
|
||||
{keysort(List, List2)},
|
||||
list::as_difflist(List2, Sorted).
|
||||
|
||||
|
||||
last(List-Back, Last) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
last(Tail-Back, Head, Last).
|
||||
|
||||
|
||||
last(List, Last, Last) :-
|
||||
unify_with_occurs_check(List, Back-Back).
|
||||
|
||||
last(List-Back, _, Last) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
last(Tail-Back, Head, Last).
|
||||
|
||||
|
||||
length(List, Length) :-
|
||||
integer(Length) ->
|
||||
( integer(Length) ->
|
||||
Length >= 0,
|
||||
make_list(Length, List)
|
||||
;
|
||||
length(List, 0, Length).
|
||||
|
||||
; length(List, 0, Length)
|
||||
).
|
||||
|
||||
length(List, Length, Length) :-
|
||||
unify_with_occurs_check(List, Back-Back).
|
||||
|
||||
length(List-Back, Acc, Length) :-
|
||||
List \== Back,
|
||||
List = [_| Tail],
|
||||
Acc2 is Acc + 1,
|
||||
length(Tail-Back, Acc2, Length).
|
||||
|
||||
|
||||
make_list(0, List):-
|
||||
!,
|
||||
unify_with_occurs_check(List, Back-Back).
|
||||
|
||||
make_list(N, List-Back):-
|
||||
List \== Back,
|
||||
List = [_| Tail],
|
||||
M is N-1,
|
||||
make_list(M, Tail-Back).
|
||||
|
||||
|
||||
max(List-Back, Max) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
max(Tail-Back, Head, Max).
|
||||
|
||||
|
||||
max(List-Back, Max, Max) :-
|
||||
List == Back, !.
|
||||
|
||||
max(List-Back, Aux, Max) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
(Aux @< Head ->
|
||||
( Aux @< Head ->
|
||||
max(Tail-Back, Head, Max)
|
||||
;
|
||||
max(Tail-Back, Aux, Max)).
|
||||
|
||||
; max(Tail-Back, Aux, Max)
|
||||
).
|
||||
|
||||
member(Element, List-Back) :-
|
||||
List \== Back,
|
||||
List = [Element|_].
|
||||
|
||||
member(Element, List-Back) :-
|
||||
List \== Back,
|
||||
List = [_| Tail],
|
||||
member(Element, Tail-Back).
|
||||
|
||||
|
||||
memberchk(Element, List) :-
|
||||
once(member(Element, List)).
|
||||
|
||||
|
||||
nth0(Position, List, Element) :-
|
||||
nth(Element, List, 0, Position, _).
|
||||
|
||||
|
||||
nth0(Nth, List, Element, Tail) :-
|
||||
nth(Element, List, 0, Nth, Tail).
|
||||
|
||||
|
||||
nth1(Position, List, Element) :-
|
||||
nth(Element, List, 1, Position, _).
|
||||
|
||||
|
||||
nth1(Nth, List, Element, Tail) :-
|
||||
nth(Element, List, 1, Nth, Tail).
|
||||
|
||||
|
||||
nth(Element, List-Back, Position, Position, Tail-Back) :-
|
||||
List \== Back,
|
||||
List = [Element| Tail].
|
||||
|
||||
nth(Element, List-Back, Count, Position, Tail-Back) :-
|
||||
List \== Back,
|
||||
List = [_| List2],
|
||||
Count2 is Count + 1,
|
||||
nth(Element, List2-Back, Count2, Position, Tail-Back).
|
||||
|
||||
|
||||
min(List-Back, Min) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
min(Tail-Back, Head, Min).
|
||||
|
||||
|
||||
min(List-Back, Min, Min) :-
|
||||
List == Back, !.
|
||||
|
||||
min(List-Back, Aux, Min) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
@@ -222,30 +182,24 @@
|
||||
;
|
||||
min(Tail-Back, Aux, Min)).
|
||||
|
||||
|
||||
new(List) :-
|
||||
unify_with_occurs_check(List, Back-Back).
|
||||
|
||||
|
||||
permutation(List, Permutation) :-
|
||||
same_length(List, Permutation),
|
||||
permutation2(List, Permutation).
|
||||
|
||||
|
||||
permutation2(List1-Back1, List2-Back2) :-
|
||||
List1 == Back1,
|
||||
List2 == Back2.
|
||||
|
||||
permutation2(List1-Back1, List2-Back2) :-
|
||||
List2 \== Back2,
|
||||
List2 = [Head2| Tail2],
|
||||
select(Head2, List1-Back1, Tail1-Back1),
|
||||
permutation2(Tail1-Back1, Tail2-Back2).
|
||||
|
||||
|
||||
prefix(List, _) :-
|
||||
unify_with_occurs_check(List, Back-Back).
|
||||
|
||||
prefix(List-Back, List2-Back2) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
@@ -253,25 +207,20 @@
|
||||
List2 = [Head| Tail2],
|
||||
prefix(Tail-Back, Tail2-Back2).
|
||||
|
||||
|
||||
reverse(List-Back, Reversed-Back) :-
|
||||
same_length(List-Back, Reversed-Back),
|
||||
reverse(List-Back, Back-Back, Reversed-Back).
|
||||
|
||||
|
||||
reverse(List-Back, Reversed, Reversed) :-
|
||||
List == Back.
|
||||
|
||||
reverse(List-Back, Acc-Back, Reversed) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
reverse(Tail-Back, [Head| Acc]-Back, Reversed).
|
||||
|
||||
|
||||
same_length(List1, List2) :-
|
||||
unify_with_occurs_check(List1, Back1-Back1),
|
||||
unify_with_occurs_check(List2, Back2-Back2).
|
||||
|
||||
same_length(List1-Back1, List2-Back2) :-
|
||||
List1 \== Back1,
|
||||
List1 = [_| Tail1],
|
||||
@@ -279,11 +228,9 @@
|
||||
List2 = [_| Tail2],
|
||||
same_length(Tail1-Back1, Tail2-Back2).
|
||||
|
||||
|
||||
select(Head, List-Back, Tail-Back) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail].
|
||||
|
||||
select(Head, List-Back, List2-Back) :-
|
||||
List \== Back,
|
||||
List = [Other| Tail],
|
||||
@@ -291,40 +238,32 @@
|
||||
List2 = [Other| Tail2],
|
||||
select(Head, Tail-Back, Tail2-Back).
|
||||
|
||||
|
||||
sort(Difflist, Sorted) :-
|
||||
as_list(Difflist, List),
|
||||
{sort(List, List2)},
|
||||
list::as_difflist(List2, Sorted).
|
||||
|
||||
|
||||
sublist(Sublist, List) :-
|
||||
unify_with_occurs_check(Sublist, List).
|
||||
|
||||
sublist(Sublist-Back, List-Back):-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
sublist(Tail-Back, Head, Sublist-Back).
|
||||
|
||||
|
||||
sublist(List, _, Sublist) :-
|
||||
unify_with_occurs_check(List, Sublist).
|
||||
|
||||
sublist(List-Back, _, Sublist-Back):-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
sublist(Tail-Back, Head, Sublist-Back).
|
||||
|
||||
sublist(List-Back, Element, [Element| Sublist]-Back):-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
sublist(Tail-Back, Head, Sublist-Back).
|
||||
|
||||
|
||||
subtract(List-Back, _, Result) :-
|
||||
unify_with_occurs_check(Result, Back-Back),
|
||||
List == Back, !.
|
||||
|
||||
subtract(List-Back, Ys, List2-Back) :-
|
||||
List \== Back,
|
||||
List = [Head| Tail],
|
||||
@@ -334,29 +273,23 @@
|
||||
List2 = [Head| Tail2],
|
||||
subtract(Tail-Back, Ys, Tail2-Back)).
|
||||
|
||||
|
||||
suffix(Suffix, List) :-
|
||||
unify_with_occurs_check(Suffix, List).
|
||||
|
||||
suffix(Suffix-Back, List-Back) :-
|
||||
List \== Back,
|
||||
List = [_| Tail],
|
||||
suffix(Suffix-Back, Tail-Back).
|
||||
|
||||
|
||||
valid(List) :-
|
||||
nonvar(List),
|
||||
valid2(List).
|
||||
|
||||
|
||||
valid2(List-Back) :-
|
||||
List == Back,
|
||||
!.
|
||||
|
||||
valid2(List-Back) :-
|
||||
nonvar(List),
|
||||
List = [_| Tail],
|
||||
valid2(Tail-Back).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -3,63 +3,46 @@
|
||||
implements(event_dbgp, monitoring),
|
||||
imports(monitor)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
date is 2006/12/15,
|
||||
author is 'Paulo Moura',
|
||||
comment is 'Debugging facilities similar to those found in most Prolog compilers.']).
|
||||
|
||||
|
||||
:- initialization(::init).
|
||||
|
||||
|
||||
:- protected(port_output/4).
|
||||
|
||||
:- mode(port_output(+atom, +object, @callable, +object), one).
|
||||
|
||||
:- info(port_output/4, [
|
||||
comment is 'Outputs current port information.',
|
||||
argnames is ['Port', 'Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
:- protected(execute_option/1).
|
||||
|
||||
:- mode(execute_option(+atom), one).
|
||||
|
||||
:- info(execute_option/1, [
|
||||
comment is 'Executes a user option at a debugger port.',
|
||||
argnames is ['Option']]).
|
||||
|
||||
|
||||
:- protected(query_user/1).
|
||||
|
||||
:- mode(query_user(-atom), one).
|
||||
|
||||
:- info(query_user/1, [
|
||||
comment is 'Query a user about an option at a debugger port.',
|
||||
argnames is ['Option']]).
|
||||
|
||||
|
||||
:- private(stream_/2).
|
||||
:- dynamic(stream_/2).
|
||||
|
||||
:- mode(stream_(?atom, ?stream), zero_or_more).
|
||||
|
||||
:- info(stream/2, [
|
||||
comment is 'Stores the current debugger input and ouput streams.',
|
||||
argnames is ['Kind', 'Stream']]).
|
||||
|
||||
|
||||
stream(Name, Stream) :-
|
||||
::stream_(Name, Stream).
|
||||
|
||||
|
||||
set_stream(Name, Stream) :-
|
||||
::retractall(stream_(Name, _)),
|
||||
::assertz(stream_(Name, Stream)).
|
||||
|
||||
|
||||
trace :-
|
||||
self(Self),
|
||||
abolish_events(before, _, _, _, Self),
|
||||
@@ -67,25 +50,20 @@
|
||||
define_events(before, _, _, _, Self),
|
||||
define_events(after, _, _, _, Self).
|
||||
|
||||
|
||||
notrace :-
|
||||
self(Self),
|
||||
abolish_events(before, _, _, _, Self),
|
||||
abolish_events(after, _, _, _, Self).
|
||||
|
||||
|
||||
debugging :-
|
||||
::monitor_activated.
|
||||
|
||||
|
||||
debug :-
|
||||
::activate_monitor.
|
||||
|
||||
|
||||
nodebug :-
|
||||
::suspend_monitor.
|
||||
|
||||
|
||||
port_output(Port, Object, Message, Sender) :-
|
||||
::stream(output, Output),
|
||||
write(Output, Port),
|
||||
@@ -97,7 +75,6 @@
|
||||
writeq(Output, Sender),
|
||||
nl(Output).
|
||||
|
||||
|
||||
query_user(Option) :-
|
||||
::stream(output, Output),
|
||||
::stream(input, Input),
|
||||
@@ -105,21 +82,18 @@
|
||||
write(Output, ' >> '),
|
||||
read(Input, Option),
|
||||
nl(Output),
|
||||
(valid_option(Option) ->
|
||||
( valid_option(Option) ->
|
||||
true
|
||||
;
|
||||
::execute_option(h), fail),
|
||||
; ::execute_option(h),
|
||||
fail
|
||||
),
|
||||
!.
|
||||
|
||||
|
||||
execute_option(c).
|
||||
|
||||
execute_option(f) :-
|
||||
!, fail.
|
||||
|
||||
execute_option(n) :-
|
||||
::nodebug.
|
||||
|
||||
execute_option(b) :-
|
||||
::stream(output,Output),
|
||||
::stream(input, Input),
|
||||
@@ -128,17 +102,15 @@
|
||||
read(Input, Goal),
|
||||
writeq(Output, Goal),
|
||||
nl(Output),
|
||||
(once(Goal) ->
|
||||
( once(Goal) ->
|
||||
write(Output, ' answer: '),
|
||||
writeq(Output, Goal), nl(Output)
|
||||
;
|
||||
write(Output, ' no'), nl(Output)),
|
||||
; write(Output, ' no'), nl(Output)
|
||||
),
|
||||
Goal = true,
|
||||
!.
|
||||
|
||||
execute_option(a) :-
|
||||
throw(error(logtalk_execution_aborted)).
|
||||
|
||||
execute_option(h) :-
|
||||
::stream(output, Output),
|
||||
write(Output, ' Available options are:'), nl(Output),
|
||||
@@ -150,26 +122,22 @@
|
||||
write(Output, ' h - help (prints this list of options)'), nl(Output),
|
||||
nl(Output).
|
||||
|
||||
|
||||
valid_option(c).
|
||||
valid_option(f).
|
||||
valid_option(n).
|
||||
valid_option(b).
|
||||
valid_option(a).
|
||||
|
||||
|
||||
before(Object, Message, Sender) :-
|
||||
::port_output(call, Object, Message, Sender),
|
||||
::query_user(Option),
|
||||
::execute_option(Option).
|
||||
|
||||
|
||||
after(Object, Message, Sender) :-
|
||||
::port_output(exit, Object, Message, Sender),
|
||||
::query_user(Option),
|
||||
::execute_option(Option).
|
||||
|
||||
|
||||
init :-
|
||||
::reset_monitor,
|
||||
current_input(Input),
|
||||
@@ -177,5 +145,4 @@
|
||||
current_output(Output),
|
||||
::set_stream(output, Output).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,78 +1,52 @@
|
||||
|
||||
:- protocol(event_dbgp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
date is 2000/7/24,
|
||||
author is 'Paulo Moura',
|
||||
comment is 'Debugging protocol similar to those found in most Prolog compilers.']).
|
||||
|
||||
|
||||
:- public(trace/0).
|
||||
|
||||
:- mode(trace, one).
|
||||
|
||||
:- info(trace/0, [
|
||||
comment is 'Starts tracing all message sending events.']).
|
||||
|
||||
|
||||
:- public(notrace/0).
|
||||
|
||||
:- mode(notrace, one).
|
||||
|
||||
:- info(notrace/0, [
|
||||
comment is 'Stops tracing.']).
|
||||
|
||||
|
||||
:- public(debug/0).
|
||||
|
||||
:- mode(debug, one).
|
||||
|
||||
:- info(debug/0, [
|
||||
comment is 'Activates spy points and starts debugging.']).
|
||||
|
||||
|
||||
:- public(nodebug/0).
|
||||
|
||||
:- mode(nodebug, one).
|
||||
|
||||
:- info(nodebug/0, [
|
||||
comment is 'Suspends spy points and stops debugging.']).
|
||||
|
||||
|
||||
:- public(debugging/0).
|
||||
|
||||
:- mode(debugging, zero_or_one).
|
||||
|
||||
:- info(debugging/0, [
|
||||
comment is 'True if the debugger is active.']).
|
||||
|
||||
|
||||
:- public(init/0).
|
||||
|
||||
:- mode(init, one).
|
||||
|
||||
:- info(init/0, [
|
||||
comment is 'Initializes debugger, turns debugging off and resets all spy points and streams.']).
|
||||
|
||||
|
||||
:- public(stream/2).
|
||||
|
||||
:- mode(stream(?atom, ?stream), zero_or_more).
|
||||
|
||||
:- info(stream/2, [
|
||||
comment is 'Current debugger input or ouput streams.',
|
||||
argnames is ['Kind', 'Stream']]).
|
||||
|
||||
|
||||
:- public(set_stream/2).
|
||||
|
||||
:- mode(set_stream(+atom, +stream), one).
|
||||
|
||||
:- info(set_stream/2, [
|
||||
comment is 'Sets the debugger input or output stream.',
|
||||
argnames is ['Kind', 'Stream']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,30 +1,22 @@
|
||||
|
||||
:- protocol(event_handlersp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2003/2/12,
|
||||
comment is 'Event handlers protocol.']).
|
||||
|
||||
|
||||
:- public(before/3).
|
||||
|
||||
:- mode(before(@object, @nonvar, @object), zero_or_one).
|
||||
|
||||
:- info(before/3, [
|
||||
comment is 'Before event handler.',
|
||||
argnames is ['Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
:- public(after/3).
|
||||
|
||||
:- mode(after(@object, @nonvar, @object), zero_or_one).
|
||||
|
||||
:- info(after/3, [
|
||||
comment is 'After event handler.',
|
||||
argnames is ['Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,14 +2,12 @@
|
||||
:- object(event_registry,
|
||||
implements(event_registryp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Before and after events registry predicates.']).
|
||||
|
||||
|
||||
monitors(Monitors) :-
|
||||
findall(
|
||||
Monitor,
|
||||
@@ -18,7 +16,6 @@
|
||||
List),
|
||||
{sort(List, Monitors)}.
|
||||
|
||||
|
||||
monitored(Objects) :-
|
||||
findall(
|
||||
Object,
|
||||
@@ -27,25 +24,20 @@
|
||||
List),
|
||||
{sort(List, Objects)}.
|
||||
|
||||
|
||||
monitor(Object, Message, Sender, Monitor) :-
|
||||
current_event(before, Object, Message, Sender, Monitor),
|
||||
current_event(after, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
set_monitor(Object, Message, Sender, Monitor) :-
|
||||
define_events(before, Object, Message, Sender, Monitor),
|
||||
define_events(after, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
del_monitors(Object, Message, Sender, Monitor) :-
|
||||
abolish_events(before, Object, Message, Sender, Monitor),
|
||||
abolish_events(after, Object, Message, Sender, Monitor).
|
||||
|
||||
|
||||
del_monitors :-
|
||||
abolish_events(before, _, _, _, _),
|
||||
abolish_events(after, _, _, _, _).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,65 +1,45 @@
|
||||
|
||||
:- protocol(event_registryp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Event registry protocol.']).
|
||||
|
||||
|
||||
:- public(monitors/1).
|
||||
|
||||
:- mode(monitors(-list), one).
|
||||
|
||||
:- info(monitors/1, [
|
||||
comment is 'Returns a list of all current monitors.',
|
||||
argnames is ['Monitors']]).
|
||||
|
||||
|
||||
:- public(monitored/1).
|
||||
|
||||
:- mode(monitored(-list), one).
|
||||
|
||||
:- info(monitored/1, [
|
||||
comment is 'Returns a list of all currently monitored objects.',
|
||||
argnames is ['Objects']]).
|
||||
|
||||
|
||||
:- public(monitor/4).
|
||||
|
||||
:- mode(monitor(?object, ?nonvar, ?object, ?object), zero_or_more).
|
||||
|
||||
:- info(monitor/4, [
|
||||
comment is 'True if the arguments describe a currently defined monitored event.',
|
||||
argnames is ['Object', 'Message', 'Sender', 'Monitor']]).
|
||||
|
||||
|
||||
:- public(set_monitor/4).
|
||||
|
||||
:- mode(set_monitor(?object, ?nonvar, ?object, +object), zero_or_one).
|
||||
|
||||
:- info(set_monitor/4, [
|
||||
comment is 'Sets a monitor for the set of matching events.',
|
||||
argnames is ['Object', 'Message', 'Sender', 'Monitor']]).
|
||||
|
||||
|
||||
:- public(del_monitors/4).
|
||||
|
||||
:- mode(del_monitors(?object, ?nonvar, ?object, ?object), one).
|
||||
|
||||
:- info(del_monitors/4, [
|
||||
comment is 'Deletes all matching monitored events.',
|
||||
argnames is ['Object', 'Message', 'Sender', 'Monitor']]).
|
||||
|
||||
|
||||
:- public(del_monitors/0).
|
||||
|
||||
:- mode(del_monitors, one).
|
||||
|
||||
:- info(del_monitors/0, [
|
||||
comment is 'Deletes all monitored events.']).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this library load the events_loader.lgt utility
|
||||
|
@@ -4,4 +4,4 @@
|
||||
event_handlersp,
|
||||
event_registryp, event_registry,
|
||||
before_event_registry, after_event_registry,
|
||||
monitorp, monitor])).
|
||||
monitorp, monitor], [events(on), reload(skip)])).
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
This folder contains objects, categories, and protocols whose
|
||||
implementation is Prolog-compiler dependent. Each sub-folder
|
||||
|
@@ -2,16 +2,13 @@
|
||||
:- object(float,
|
||||
extends(number)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Floating point numbers data type predicates.']).
|
||||
|
||||
|
||||
valid(Float) :-
|
||||
float(Float).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this group load the hierarchies_loader.lgt
|
||||
|
@@ -3,4 +3,4 @@
|
||||
logtalk_load([
|
||||
hierarchyp,
|
||||
proto_hierarchyp, proto_hierarchy,
|
||||
class_hierarchyp, class_hierarchy])).
|
||||
class_hierarchyp, class_hierarchy], [reload(skip)])).
|
||||
|
@@ -1,66 +1,46 @@
|
||||
|
||||
:- protocol(hierarchyp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Common hierarchy protocol for prototype and class hierarchies.']).
|
||||
|
||||
|
||||
:- public(ancestor/1).
|
||||
|
||||
:- mode(ancestor(?object), zero_or_more).
|
||||
|
||||
:- info(ancestor/1, [
|
||||
comment is 'Returns, by backtracking, all object ancestors.',
|
||||
argnames is ['Ancestor']]).
|
||||
|
||||
|
||||
:- public(ancestors/1).
|
||||
|
||||
:- mode(ancestors(-list), one).
|
||||
|
||||
:- info(ancestors/1, [
|
||||
comment is 'List of all object ancestors.',
|
||||
argnames is ['Ancestors']]).
|
||||
|
||||
|
||||
:- public(leaf/1).
|
||||
|
||||
:- mode(leaf(?object), zero_or_more).
|
||||
|
||||
:- info(leaf/1, [
|
||||
comment is 'Returns, by backtracking, all object leaves.',
|
||||
argnames is ['Leaf']]).
|
||||
|
||||
|
||||
:- public(leaves/1).
|
||||
|
||||
:- mode(leaves(-list), one).
|
||||
|
||||
:- info(leaves/1, [
|
||||
comment is 'List of all object leaves.',
|
||||
argnames is ['Leaves']]).
|
||||
|
||||
|
||||
:- public(descendant/1).
|
||||
|
||||
:- mode(descendant(?object), zero_or_more).
|
||||
|
||||
:- info(descendant/1, [
|
||||
comment is 'Returns, by backtracking, all object descendants.',
|
||||
argnames is ['Descendant']]).
|
||||
|
||||
|
||||
:- public(descendants/1).
|
||||
|
||||
:- mode(descendants(-list), one).
|
||||
|
||||
:- info(descendants/1, [
|
||||
comment is 'List of all object descendants.',
|
||||
argnames is ['Descendants']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,45 +2,37 @@
|
||||
:- object(integer,
|
||||
extends(number)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
date is 2007/4/20,
|
||||
comment is 'Integer data type predicates.']).
|
||||
|
||||
|
||||
:- public(between/3).
|
||||
|
||||
:- mode(between(+integer, +integer, ?integer), zero_or_more).
|
||||
|
||||
:- mode(between(+integer, +integer, +integer), zero_or_one).
|
||||
:- mode(between(+integer, +integer, -integer), zero_or_more).
|
||||
:- info(between/3, [
|
||||
comment is 'Returns integers in the interval defined by the two first arguments.',
|
||||
argnames is ['Lower', 'Upper', 'Integer']]).
|
||||
|
||||
|
||||
between(Lower, Upper, Integer) :-
|
||||
integer(Lower),
|
||||
integer(Upper),
|
||||
(var(Integer) ->
|
||||
( var(Integer) ->
|
||||
Lower =< Upper,
|
||||
generate(Lower, Upper, Integer)
|
||||
;
|
||||
integer(Integer),
|
||||
; integer(Integer),
|
||||
Lower =< Integer,
|
||||
Integer =< Upper).
|
||||
|
||||
Integer =< Upper
|
||||
).
|
||||
|
||||
generate(Lower, _, Lower).
|
||||
|
||||
generate(Lower, Upper, Integer) :-
|
||||
Lower < Upper,
|
||||
Next is Lower + 1,
|
||||
generate(Next, Upper, Integer).
|
||||
|
||||
|
||||
valid(Integer) :-
|
||||
integer(Integer).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -3,37 +3,30 @@
|
||||
implements(listp),
|
||||
extends(compound)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.3,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/12/21,
|
||||
comment is 'List predicates.']).
|
||||
|
||||
|
||||
:- public(as_difflist/2).
|
||||
|
||||
:- mode(as_difflist(+list, -list), one).
|
||||
|
||||
:- info(as_difflist/2,
|
||||
[comment is 'Converts a list to a difference list.',
|
||||
argnames is ['List', 'Diffist']]).
|
||||
|
||||
|
||||
append([], List, List).
|
||||
|
||||
append([Head| Tail], List, [Head| Tail2]) :-
|
||||
append(Tail, List, Tail2).
|
||||
|
||||
|
||||
as_difflist([], Back-Back).
|
||||
|
||||
as_difflist([Head| Tail], [Head| Tail2]-Back) :-
|
||||
as_difflist(Tail, Tail2-Back).
|
||||
|
||||
|
||||
delete([], _, []).
|
||||
|
||||
delete([Head| Tail], Element, Remaining) :-
|
||||
( Head == Element ->
|
||||
delete(Tail, Element, Remaining)
|
||||
@@ -41,9 +34,7 @@
|
||||
delete(Tail, Element, Tail2)
|
||||
).
|
||||
|
||||
|
||||
delete_matches([], _, []).
|
||||
|
||||
delete_matches([Head| Tail], Element, Remaining) :-
|
||||
( \+ \+ Head = Element ->
|
||||
delete_matches(Tail, Element, Remaining)
|
||||
@@ -51,44 +42,33 @@
|
||||
delete_matches(Tail, Element, Tail2)
|
||||
).
|
||||
|
||||
|
||||
empty(List) :-
|
||||
List == [].
|
||||
|
||||
|
||||
flatten(List, Flatted) :-
|
||||
flatten(List, [], Flatted).
|
||||
|
||||
|
||||
flatten(Var, Tail, [Var| Tail]) :-
|
||||
var(Var),
|
||||
!.
|
||||
|
||||
flatten([], Flatted, Flatted) :-
|
||||
!.
|
||||
|
||||
flatten([Head| Tail], List, Flatted) :-
|
||||
!,
|
||||
flatten(Tail, List, Aux),
|
||||
flatten(Head, Aux, Flatted).
|
||||
|
||||
flatten(Head, Tail, [Head| Tail]).
|
||||
|
||||
|
||||
keysort(List, Sorted) :-
|
||||
{keysort(List, Sorted)}.
|
||||
|
||||
|
||||
last([Head| Tail], Last) :-
|
||||
last(Tail, Head, Last).
|
||||
|
||||
|
||||
last([], Last, Last).
|
||||
|
||||
last([Head| Tail], _, Last) :-
|
||||
last(Tail, Head, Last).
|
||||
|
||||
|
||||
length(List, Length) :-
|
||||
( integer(Length) ->
|
||||
Length >= 0,
|
||||
@@ -96,84 +76,65 @@
|
||||
; length(List, 0, Length)
|
||||
).
|
||||
|
||||
|
||||
make_list(0, []):-
|
||||
!.
|
||||
|
||||
make_list(N, [_| Tail]):-
|
||||
M is N-1,
|
||||
make_list(M, Tail).
|
||||
|
||||
|
||||
length([], Length, Length).
|
||||
|
||||
length([_| Tail], Acc, Length) :-
|
||||
Acc2 is Acc + 1,
|
||||
length(Tail, Acc2, Length).
|
||||
|
||||
|
||||
max([N| Ns], Max) :-
|
||||
max(Ns, N, Max).
|
||||
|
||||
max([], Max, Max).
|
||||
|
||||
max([N| Ns], Aux, Max) :-
|
||||
( N @> Aux ->
|
||||
max(Ns, N, Max)
|
||||
; max(Ns, Aux, Max)
|
||||
).
|
||||
|
||||
|
||||
member(Element, [Element| _]).
|
||||
|
||||
member(Element, [_| List]) :-
|
||||
member(Element, List).
|
||||
|
||||
|
||||
memberchk(Element, [Element| _]) :-
|
||||
!.
|
||||
|
||||
memberchk(Element, [_| List]) :-
|
||||
memberchk(Element, List).
|
||||
|
||||
|
||||
min([N| Ns], Min) :-
|
||||
min(Ns, N, Min).
|
||||
|
||||
min([], Min, Min).
|
||||
|
||||
min([N| Ns], Aux, Min) :-
|
||||
( N @< Aux ->
|
||||
min(Ns, N, Min)
|
||||
; min(Ns, Aux, Min)
|
||||
).
|
||||
|
||||
|
||||
new([]).
|
||||
|
||||
|
||||
nextto(X, Y, [X, Y| _]).
|
||||
|
||||
nextto(X, Y, [_| Tail]) :-
|
||||
nextto(X, Y, Tail).
|
||||
|
||||
|
||||
nth0(Nth, List, Element) :-
|
||||
nth(Element, List, 0, Nth, _).
|
||||
|
||||
|
||||
nth0(Nth, List, Element, Tail) :-
|
||||
nth(Element, List, 0, Nth, Tail).
|
||||
|
||||
|
||||
nth1(Nth, List, Element) :-
|
||||
nth(Element, List, 1, Nth, _).
|
||||
|
||||
|
||||
nth1(Nth, List, Element, Tail) :-
|
||||
nth(Element, List, 1, Nth, Tail).
|
||||
|
||||
|
||||
nth(Element, List, Acc, Nth, Tail) :-
|
||||
( integer(Nth),
|
||||
Nth >= Acc,
|
||||
@@ -183,75 +144,53 @@
|
||||
nth_aux(Element, List, Acc, Nth, Tail)
|
||||
).
|
||||
|
||||
|
||||
nth_aux(Head, [Head| Tail], Position, Position, Tail).
|
||||
|
||||
nth_aux(Head, [_| List], Count, Position, Tail) :-
|
||||
Count2 is Count + 1,
|
||||
nth_aux(Head, List, Count2, Position, Tail).
|
||||
|
||||
|
||||
permutation(List, Permutation) :-
|
||||
same_length(List, Permutation),
|
||||
permutation2(List, Permutation).
|
||||
|
||||
|
||||
permutation2([], []).
|
||||
|
||||
permutation2(List, [Head| Tail]) :-
|
||||
select(Head, List, Remaining),
|
||||
permutation2(Remaining, Tail).
|
||||
|
||||
|
||||
prefix([], _).
|
||||
|
||||
prefix([Element| Tail], [Element| Tail2]) :-
|
||||
prefix(Tail, Tail2).
|
||||
|
||||
|
||||
reverse(List, Reversed) :-
|
||||
reverse(List, [], Reversed, Reversed).
|
||||
|
||||
|
||||
reverse([], Reversed, Reversed, []).
|
||||
|
||||
reverse([Head| Tail], List, Reversed, [_| Bound]) :-
|
||||
reverse(Tail, [Head| List], Reversed, Bound).
|
||||
|
||||
|
||||
same_length([], []).
|
||||
|
||||
same_length([_| Tail1], [_| Tail2]) :-
|
||||
same_length(Tail1, Tail2).
|
||||
|
||||
|
||||
select(Head, [Head| Tail], Tail).
|
||||
|
||||
select(Head, [Head2| Tail], [Head2| Tail2]) :-
|
||||
select(Head, Tail, Tail2).
|
||||
|
||||
|
||||
sort(List, Sorted) :-
|
||||
{sort(List, Sorted)}.
|
||||
|
||||
|
||||
sublist(List, List).
|
||||
|
||||
sublist(Sublist, [Head| Tail]):-
|
||||
sublist(Tail, Head, Sublist).
|
||||
|
||||
|
||||
sublist(Sublist, _, Sublist).
|
||||
|
||||
sublist([Head| Tail], _, Sublist):-
|
||||
sublist(Tail, Head, Sublist).
|
||||
|
||||
sublist([Head| Tail], Element, [Element| Sublist]):-
|
||||
sublist(Tail, Head, Sublist).
|
||||
|
||||
|
||||
subtract([], _, []).
|
||||
|
||||
subtract([Head| Tail], List, Rest) :-
|
||||
( ::memberchk(Head, List) ->
|
||||
subtract(Tail, List, Rest)
|
||||
@@ -259,22 +198,16 @@
|
||||
subtract(Tail, List, Tail2)
|
||||
).
|
||||
|
||||
|
||||
suffix(List, List).
|
||||
|
||||
suffix(List, [_| Tail]) :-
|
||||
suffix(List, Tail).
|
||||
|
||||
|
||||
valid(List) :-
|
||||
nonvar(List),
|
||||
\+ \+ valid2(List).
|
||||
|
||||
|
||||
valid2([]).
|
||||
|
||||
valid2([_| List]) :-
|
||||
valid2(List).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,251 +1,171 @@
|
||||
|
||||
:- protocol(listp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.2,
|
||||
author is 'Paulo Moura',
|
||||
date is 2004/5/9,
|
||||
comment is 'List protocol.']).
|
||||
|
||||
|
||||
:- public(append/3).
|
||||
|
||||
:- mode(append(?list, ?list, ?list), zero_or_more).
|
||||
|
||||
:- info(append/3, [
|
||||
comment is 'Appends two lists.',
|
||||
argnames is ['List1', 'List2', 'List']]).
|
||||
|
||||
|
||||
:- public(delete/3).
|
||||
|
||||
:- mode(delete(@list, @term, ?list), one).
|
||||
|
||||
:- info(delete/3,
|
||||
[comment is 'Deletes from a list all ocurrences of an element returning the list of remaining elements.',
|
||||
argnames is ['List', 'Element', 'Remaining']]).
|
||||
|
||||
|
||||
:- public(delete_matches/3).
|
||||
|
||||
:- mode(delete_matches(@list, @term, ?list), one).
|
||||
|
||||
:- info(delete_matches/3,
|
||||
[comment is 'Deletes all matching elements from a list, returning the list of remaining elements.',
|
||||
argnames is ['List', 'Element', 'Remaining']]).
|
||||
|
||||
|
||||
:- public(empty/1).
|
||||
|
||||
:- mode(empty(@list), zero_or_one).
|
||||
|
||||
:- info(empty/1,
|
||||
[comment is 'True if the argument is an empty list.',
|
||||
argnames is ['List']]).
|
||||
|
||||
|
||||
:- public(flatten/2).
|
||||
|
||||
:- mode(flatten(+list, -list), one).
|
||||
|
||||
:- info(flatten/2,
|
||||
[comment is 'Flattens a list of lists into a list.',
|
||||
argnames is ['List', 'Flatted']]).
|
||||
|
||||
|
||||
:- public(keysort/2).
|
||||
|
||||
:- mode(keysort(+list, -list), one).
|
||||
|
||||
:- info(keysort/2,
|
||||
[comment is 'Sorts a list of key-value pairs in ascending order.',
|
||||
argnames is ['List', 'Sorted']]).
|
||||
|
||||
|
||||
:- public(last/2).
|
||||
|
||||
:- mode(last(?list, ?term), zero_or_more).
|
||||
|
||||
:- info(last/2,
|
||||
[comment is 'List last element (if it exists).',
|
||||
argnames is ['List', 'Last']]).
|
||||
|
||||
|
||||
:- public(length/2).
|
||||
|
||||
:- mode(length(?list, ?integer), zero_or_more).
|
||||
|
||||
:- info(length/2,
|
||||
[comment is 'List length.',
|
||||
argnames is ['List', 'Length']]).
|
||||
|
||||
|
||||
:- public(max/2).
|
||||
|
||||
:- mode(max(+list, -term), zero_or_one).
|
||||
|
||||
:- info(max/2,
|
||||
[comment is 'Determines the list maximum value using standard order. Fails if the list is empty.',
|
||||
argnames is ['List', 'Maximum']]).
|
||||
|
||||
|
||||
:- public(member/2).
|
||||
|
||||
:- mode(member(?term, ?list), zero_or_more).
|
||||
|
||||
:- info(member/2,
|
||||
[comment is 'Element is a list member.',
|
||||
argnames is ['Element', 'List']]).
|
||||
|
||||
|
||||
:- public(memberchk/2).
|
||||
|
||||
:- mode(memberchk(?term, ?list), zero_or_one).
|
||||
|
||||
:- info(memberchk/2,
|
||||
[comment is 'Checks if a term is a member of a list.',
|
||||
argnames is ['Element', 'List']]).
|
||||
|
||||
|
||||
:- public(min/2).
|
||||
|
||||
:- mode(min(+list, -term), zero_or_one).
|
||||
|
||||
:- info(min/2,
|
||||
[comment is 'Determines the minimum value in a list using standard order. Fails if the list is empty.',
|
||||
argnames is ['List', 'Minimum']]).
|
||||
|
||||
|
||||
:- public(nextto/3).
|
||||
|
||||
:- mode(nextto(?term, ?term, ?list), zero_or_more).
|
||||
|
||||
:- info(nextto/3, [
|
||||
comment is 'X and Y are consecutive elements in List.',
|
||||
argnames is ['X', 'Y', 'List']]).
|
||||
|
||||
|
||||
:- public(nth0/3).
|
||||
|
||||
:- mode(nth0(?integer, ?list, ?term), zero_or_more).
|
||||
|
||||
:- info(nth0/3, [
|
||||
comment is 'Nth element of a list (counting from zero).',
|
||||
argnames is ['Nth', 'List', 'Element']]).
|
||||
|
||||
|
||||
:- public(nth0/4).
|
||||
|
||||
:- mode(nth0(?integer, ?list, ?term, ?list), zero_or_more).
|
||||
|
||||
:- info(nth0/4, [
|
||||
comment is 'Nth element of a list (counting from zero).',
|
||||
argnames is ['Nth', 'List', 'Element', 'Residue']]).
|
||||
|
||||
|
||||
:- public(nth1/3).
|
||||
|
||||
:- mode(nth1(?integer, ?list, ?term), zero_or_more).
|
||||
|
||||
:- info(nth1/3, [
|
||||
comment is 'Nth element of a list (counting from one).',
|
||||
argnames is ['Nth', 'List', 'Element']]).
|
||||
|
||||
|
||||
:- public(nth1/4).
|
||||
|
||||
:- mode(nth1(?integer, ?list, ?term, ?list), zero_or_more).
|
||||
|
||||
:- info(nth1/4, [
|
||||
comment is 'Nth element of a list (counting from zero).',
|
||||
argnames is ['Nth', 'List', 'Element', 'Residue']]).
|
||||
|
||||
|
||||
:- public(permutation/2).
|
||||
|
||||
:- mode(permutation(?list, ?list), zero_or_more).
|
||||
|
||||
:- info(permutation/2,
|
||||
[comment is 'The two lists are a permutation of the same list.',
|
||||
argnames is ['List', 'Permutation']]).
|
||||
|
||||
|
||||
:- public(prefix/2).
|
||||
|
||||
:- mode(prefix(?list, +list), zero_or_more).
|
||||
|
||||
:- info(prefix/2,
|
||||
[comment is 'Prefix is a prefix of List.',
|
||||
argnames is ['Prefix', 'List']]).
|
||||
|
||||
|
||||
:- public(reverse/2).
|
||||
|
||||
:- mode(reverse(+list, ?list), zero_or_one).
|
||||
:- mode(reverse(?list, +list), zero_or_one).
|
||||
:- mode(reverse(-list, -list), one_or_more).
|
||||
|
||||
:- info(reverse/2,
|
||||
[comment is 'Reverses a list.',
|
||||
argnames is ['List', 'Reversed']]).
|
||||
|
||||
|
||||
:- public(same_length/2).
|
||||
|
||||
:- mode(same_length(+list, ?list), zero_or_one).
|
||||
:- mode(same_length(?list, +list), zero_or_one).
|
||||
:- mode(same_length(-list, -list), one_or_more).
|
||||
|
||||
:- info(same_length/2,
|
||||
[comment is 'The two lists have the same length.',
|
||||
argnames is ['List1', 'List2']]).
|
||||
|
||||
|
||||
:- public(select/3).
|
||||
|
||||
:- mode(select(?term, +list, ?list), zero_or_more).
|
||||
:- mode(select(?term, ?list, +list), zero_or_more).
|
||||
|
||||
:- info(select/3,
|
||||
[comment is 'Selects an element from a list, returning the list of remaining elements.',
|
||||
argnames is ['Element', 'List', 'Remaining']]).
|
||||
|
||||
|
||||
:- public(sort/2).
|
||||
|
||||
:- mode(sort(+list, -list), one).
|
||||
|
||||
:- info(sort/2,
|
||||
[comment is 'Sorts a list in ascending order.',
|
||||
argnames is ['List', 'Sorted']]).
|
||||
|
||||
|
||||
:- public(sublist/2).
|
||||
|
||||
:- mode(sublist(?list, +list), zero_or_more).
|
||||
|
||||
:- info(sublist/2,
|
||||
[comment is 'The first list is a sublist of the second.',
|
||||
argnames is ['Sublist', 'List']]).
|
||||
|
||||
|
||||
:- public(subtract/3).
|
||||
|
||||
:- mode(subtract(+list, +list, -list), one).
|
||||
|
||||
:- info(subtract/3,
|
||||
[comment is 'Removes all elements in the second list from the first list, returning the list of remaining elements.',
|
||||
argnames is ['List', 'Elements', 'Remaining']]).
|
||||
|
||||
|
||||
:- public(suffix/2).
|
||||
|
||||
:- mode(suffix(?list, +list), zero_or_more).
|
||||
|
||||
:- info(suffix/2,
|
||||
[comment is 'Suffix is a suffix of List.',
|
||||
argnames is ['Suffix', 'List']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,74 +2,59 @@
|
||||
:- object(loop,
|
||||
implements(loopp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/9/17,
|
||||
comment is 'Loop control structures predicates.']).
|
||||
|
||||
:- meta_predicate(whiledo(::, ::)).
|
||||
whiledo(Condition, Action) :-
|
||||
( call(Condition) ->
|
||||
\+ \+ call(Action),
|
||||
whiledo(Condition, Action)
|
||||
; true
|
||||
).
|
||||
|
||||
:- meta_predicate(dowhile(::, ::)).
|
||||
|
||||
:- meta_predicate(forto(*, *, ::)).
|
||||
|
||||
:- meta_predicate(forto(*, *, *, ::)).
|
||||
|
||||
:- meta_predicate(fordownto(*, *, ::)).
|
||||
|
||||
:- meta_predicate(fordownto(*, *, *, ::)).
|
||||
|
||||
:- meta_predicate(whiledo(::, ::)).
|
||||
|
||||
|
||||
dowhile(Action, Condition) :-
|
||||
\+ \+ call(Action),
|
||||
whiledo(Condition, Action).
|
||||
|
||||
|
||||
whiledo(Condition, Action) :-
|
||||
call(Condition) ->
|
||||
\+ \+ call(Action),
|
||||
whiledo(Condition, Action)
|
||||
;
|
||||
true.
|
||||
|
||||
|
||||
:- meta_predicate(forto(*, *, ::)).
|
||||
forto(First, Last, Call) :-
|
||||
First =< Last ->
|
||||
( First =< Last ->
|
||||
\+ \+ call(Call),
|
||||
Next is First + 1,
|
||||
forto(Next, Last, Call)
|
||||
;
|
||||
true.
|
||||
|
||||
; true
|
||||
).
|
||||
|
||||
:- meta_predicate(forto(*, *, *, ::)).
|
||||
forto(Count, First, Last, Call) :-
|
||||
First =< Last ->
|
||||
( First =< Last ->
|
||||
\+ \+ (Count = First, call(Call)),
|
||||
Next is First + 1,
|
||||
forto(Count, Next, Last, Call)
|
||||
;
|
||||
true.
|
||||
|
||||
; true
|
||||
).
|
||||
|
||||
:- meta_predicate(fordownto(*, *, ::)).
|
||||
fordownto(First, Last, Call) :-
|
||||
First >= Last ->
|
||||
( First >= Last ->
|
||||
\+ \+ call(Call),
|
||||
Next is First - 1,
|
||||
fordownto(Next, Last, Call)
|
||||
;
|
||||
true.
|
||||
|
||||
; true
|
||||
).
|
||||
|
||||
:- meta_predicate(fordownto(*, *, *, ::)).
|
||||
fordownto(Count, First, Last, Call) :-
|
||||
First >= Last ->
|
||||
( First >= Last ->
|
||||
\+ \+ (Count = First, call(Call)),
|
||||
Next is First - 1,
|
||||
fordownto(Count, Next, Last, Call)
|
||||
;
|
||||
true.
|
||||
|
||||
; true
|
||||
).
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,72 +1,52 @@
|
||||
|
||||
:- protocol(loopp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/9/17,
|
||||
comment is 'Loop control structures protocol.']).
|
||||
|
||||
|
||||
:- public(dowhile/2).
|
||||
:- meta_predicate(dowhile(::, ::)).
|
||||
|
||||
:- mode(dowhile(+callable, @callable), zero_or_one).
|
||||
|
||||
:- info(dowhile/2, [
|
||||
comment is 'Do Action while Condition is true.',
|
||||
argnames is ['Action', 'Condition']]).
|
||||
|
||||
|
||||
:- public(forto/3).
|
||||
:- meta_predicate(forto(*, *, ::)).
|
||||
|
||||
:- mode(forto(+integer, +integer, @callable), zero_or_one).
|
||||
|
||||
:- info(forto/3, [
|
||||
comment is 'Counting from First to Last do Call.',
|
||||
argnames is ['First', 'Last', 'Call']]).
|
||||
|
||||
|
||||
:- public(forto/4).
|
||||
:- meta_predicate(forto(*, *, *, ::)).
|
||||
|
||||
:- mode(forto(-integer, +integer, +integer, @callable), zero_or_one).
|
||||
|
||||
:- info(forto/4, [
|
||||
comment is 'Do Call counting from First to Last and instantiating Count to each sucessive value.',
|
||||
argnames is ['Count', 'First', 'Last', 'Call']]).
|
||||
|
||||
|
||||
:- public(fordownto/3).
|
||||
:- meta_predicate(fordownto(*, *, ::)).
|
||||
|
||||
:- mode(fordownto(+integer, +integer, @callable), zero_or_one).
|
||||
|
||||
:- info(fordownto/3, [
|
||||
comment is 'Counting from First to Last do Call.',
|
||||
argnames is ['First', 'Last', 'Call']]).
|
||||
|
||||
|
||||
:- public(fordownto/4).
|
||||
:- meta_predicate(fordownto(*, *, *, ::)).
|
||||
|
||||
:- mode(fordownto(-integer, +integer, +integer, @callable), zero_or_one).
|
||||
|
||||
:- info(fordownto/4, [
|
||||
comment is 'Do Call counting from First to Last and instantiating Count to each sucessive value.',
|
||||
argnames is ['Count', 'First', 'Last', 'Call']]).
|
||||
|
||||
|
||||
:- public(whiledo/2).
|
||||
:- meta_predicate(whiledo(::, ::)).
|
||||
|
||||
:- mode(whiledo(+callable, @callable), zero_or_one).
|
||||
|
||||
:- info(whiledo/2, [
|
||||
comment is 'While Condition is true do Action.',
|
||||
argnames is ['Condition', 'Action']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this group load the metapredicates_loader.lgt
|
||||
|
@@ -1,5 +1,3 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([
|
||||
metap, meta,
|
||||
loopp, loop])).
|
||||
logtalk_load([metap, meta, loopp, loop], [reload(skip)])).
|
||||
|
@@ -2,29 +2,23 @@
|
||||
:- category(monitor,
|
||||
implements(monitorp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2004/3/31,
|
||||
comment is 'Monitor predicates.']).
|
||||
|
||||
|
||||
:- private(spy_point_/4).
|
||||
:- dynamic(spy_point_/4).
|
||||
|
||||
:- mode(spy_point_(?event, ?object, ?callable, ?object), zero_or_more).
|
||||
|
||||
:- info(spy_point_/4, [
|
||||
comment is 'Stores current spy points.',
|
||||
argnames is ['Event', 'Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
monitor_activated :-
|
||||
self(Self),
|
||||
once(current_event(_, _, _, _, Self)).
|
||||
|
||||
|
||||
activate_monitor :-
|
||||
self(Self),
|
||||
abolish_events(before, _, _, _, Self),
|
||||
@@ -33,32 +27,26 @@
|
||||
::spy_point_(Event, Object, Message, Sender),
|
||||
define_events(Event, Object, Message, Sender, Self)).
|
||||
|
||||
|
||||
suspend_monitor :-
|
||||
self(Self),
|
||||
abolish_events(before, _, _, _, Self),
|
||||
abolish_events(after, _, _, _, Self).
|
||||
|
||||
|
||||
reset_monitor :-
|
||||
self(Self),
|
||||
abolish_events(before, _, _, _, Self),
|
||||
abolish_events(after, _, _, _, Self),
|
||||
::retractall(spy_point_(_, _, _, _)).
|
||||
|
||||
|
||||
spy_point(Event, Object, Message, Sender) :-
|
||||
::spy_point_(Event, Object, Message, Sender).
|
||||
|
||||
|
||||
set_spy_point(Event, Object, Message, Sender) :-
|
||||
::retractall(spy_point_(Event, Object, Message, Sender)),
|
||||
once((var(Event); Event = before; Event = after)),
|
||||
::assertz(spy_point_(Event, Object, Message, Sender)).
|
||||
|
||||
|
||||
del_spy_points(Event, Object, Message, Sender) :-
|
||||
::retractall(spy_point_(Event, Object, Message, Sender)).
|
||||
|
||||
|
||||
:- end_category.
|
||||
|
@@ -1,71 +1,48 @@
|
||||
|
||||
:- protocol(monitorp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Monitor protocol.']).
|
||||
|
||||
|
||||
:- public(monitor_activated/0).
|
||||
|
||||
:- mode(monitor_activated, zero_or_one).
|
||||
|
||||
:- info(monitor_activated/0, [
|
||||
comment is 'True if monitor is currently active.']).
|
||||
|
||||
|
||||
:- public(activate_monitor/0).
|
||||
|
||||
:- mode(activate_monitor, one).
|
||||
|
||||
:- info(activate_monitor/0, [
|
||||
comment is 'Activates all spy points and start monitoring.']).
|
||||
|
||||
|
||||
:- public(suspend_monitor/0).
|
||||
|
||||
:- mode(suspend_monitor, one).
|
||||
|
||||
:- info(suspend_monitor/0, [
|
||||
comment is 'Suspends monitoring, deactivating all spy points.']).
|
||||
|
||||
|
||||
:- public(reset_monitor/0).
|
||||
|
||||
:- mode(reset_monitor, one).
|
||||
|
||||
:- info(reset_monitor/0, [
|
||||
comment is 'Resets monitor, deactivating and deleting all spy points.']).
|
||||
|
||||
|
||||
:- public(spy_point/4).
|
||||
|
||||
:- mode(spy_point(?event, ?object, ?callable, ?object), zero_or_more).
|
||||
|
||||
:- info(spy_point/4, [
|
||||
comment is 'Current spy point.',
|
||||
argnames is ['Event', 'Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
:- public(set_spy_point/4).
|
||||
|
||||
:- mode(set_spy_point(?event, ?object, ?callable, ?object), one).
|
||||
|
||||
:- info(set_spy_point/4, [
|
||||
comment is 'Sets a spy point.',
|
||||
argnames is ['Event', 'Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
:- public(del_spy_points/4).
|
||||
|
||||
:- mode(del_spy_points(@event, @object, @callable, @object), one).
|
||||
|
||||
:- info(del_spy_points/4, [
|
||||
comment is 'Deletes all matching spy points.',
|
||||
argnames is ['Event', 'Object', 'Message', 'Sender']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,23 +2,19 @@
|
||||
:- object(natural,
|
||||
extends(integer)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Natural numbers data type predicates.']).
|
||||
|
||||
|
||||
between(Lower, Upper, Integer) :-
|
||||
integer(Lower),
|
||||
Lower > 0,
|
||||
^^between(Lower, Upper, Integer).
|
||||
|
||||
|
||||
valid(Natural) :-
|
||||
integer(Natural),
|
||||
Natural > 0.
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -2,16 +2,13 @@
|
||||
:- object(number,
|
||||
extends(atomic)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Number data type predicates.']).
|
||||
|
||||
|
||||
valid(Number) :-
|
||||
number(Number).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -3,74 +3,66 @@
|
||||
implements(numberlistp),
|
||||
extends(list)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
date is 2007/4/20,
|
||||
comment is 'List of numbers predicates.']).
|
||||
|
||||
|
||||
average([], 0).
|
||||
|
||||
average([], 0.0).
|
||||
average([N| Ns], Average) :-
|
||||
average([N| Ns], 0, 0, Average).
|
||||
|
||||
average(Ns, 1, N, Average).
|
||||
|
||||
average([], Length, Sum, Average) :-
|
||||
Average is Sum / Length.
|
||||
|
||||
average([N| Ns], Lacc, Sacc, Average) :-
|
||||
Lacc2 is Lacc + 1,
|
||||
Sacc2 is Sacc + N,
|
||||
average(Ns, Lacc2, Sacc2, Average).
|
||||
|
||||
|
||||
min([N| Ns], Min) :-
|
||||
min(Ns, N, Min).
|
||||
|
||||
min([], Min, Min).
|
||||
|
||||
min([N| Ns], Aux, Min) :-
|
||||
N < Aux ->
|
||||
( N < Aux ->
|
||||
min(Ns, N, Min)
|
||||
;
|
||||
min(Ns, Aux, Min).
|
||||
|
||||
; min(Ns, Aux, Min)
|
||||
).
|
||||
|
||||
max([N| Ns], Max) :-
|
||||
max(Ns, N, Max).
|
||||
|
||||
max([], Max, Max).
|
||||
|
||||
max([N| Ns], Aux, Max) :-
|
||||
N > Aux ->
|
||||
( N > Aux ->
|
||||
max(Ns, N, Max)
|
||||
;
|
||||
max(Ns, Aux, Max).
|
||||
; max(Ns, Aux, Max)
|
||||
).
|
||||
|
||||
product(List, Product) :-
|
||||
product(List, 1, Product).
|
||||
|
||||
product([], Product, Product).
|
||||
product([N| Ns], Acc, Product) :-
|
||||
Acc2 is Acc * N,
|
||||
product(Ns, Acc2, Product).
|
||||
|
||||
sum(List, Sum) :-
|
||||
sum(List, 0, Sum).
|
||||
|
||||
|
||||
sum([], Sum, Sum).
|
||||
|
||||
sum([N| Ns], Acc, Sum) :-
|
||||
Acc2 is Acc + N,
|
||||
sum(Ns, Acc2, Sum).
|
||||
|
||||
|
||||
valid(List) :-
|
||||
nonvar(List),
|
||||
\+ \+ valid2(List).
|
||||
|
||||
|
||||
valid2([]).
|
||||
|
||||
valid2([Head| Tail]) :-
|
||||
number(Head),
|
||||
valid2(Tail).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,30 +1,28 @@
|
||||
|
||||
:- protocol(numberlistp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
date is 2007/4/20,
|
||||
comment is 'List of numbers protocol.']).
|
||||
|
||||
:- public(product/2).
|
||||
:- mode(product(+list(number), ?number), zero_or_one).
|
||||
:- info(product/2,
|
||||
[comment is 'Calculates the product of all list values.',
|
||||
argnames is ['List', 'Product']]).
|
||||
|
||||
:- public(sum/2).
|
||||
|
||||
:- mode(sum(+list, ?number), zero_or_one).
|
||||
|
||||
:- mode(sum(+list(number), ?number), zero_or_one).
|
||||
:- info(sum/2,
|
||||
[comment is 'Calculates the sum of all list values.',
|
||||
argnames is ['List', 'Sum']]).
|
||||
|
||||
|
||||
:- public(average/2).
|
||||
|
||||
:- mode(average(+list, ?number), zero_or_one).
|
||||
|
||||
:- mode(average(+list(number), ?float), zero_or_one).
|
||||
:- info(average/2,
|
||||
[comment is 'Calculates the average of a list of values.',
|
||||
argnames is ['List', 'Average']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,66 +2,53 @@
|
||||
:- category(proto_hierarchy,
|
||||
implements(proto_hierarchyp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2006/2/20,
|
||||
comment is 'Prototype hierarchy predicates.']).
|
||||
|
||||
|
||||
parent(Parent) :-
|
||||
self(Self),
|
||||
extends_object(Self, Parent).
|
||||
|
||||
|
||||
parents(Parents) :-
|
||||
self(Self),
|
||||
findall(Parent, extends_object(Self, Parent), Parents).
|
||||
|
||||
|
||||
ancestor(Ancestor) :-
|
||||
self(Self),
|
||||
ancestor(Self, Ancestor).
|
||||
|
||||
|
||||
ancestor(Self, Ancestor) :-
|
||||
extends_object(Self, Ancestor).
|
||||
|
||||
ancestor(Self, Ancestor) :-
|
||||
extends_object(Self, Parent),
|
||||
ancestor(Parent, Ancestor).
|
||||
|
||||
|
||||
ancestors(Ancestors) :-
|
||||
self(Self),
|
||||
findall(Ancestor, ancestor(Self, Ancestor), Ancestors).
|
||||
|
||||
|
||||
extension(Prototype) :-
|
||||
self(Self),
|
||||
extends_object(Prototype, Self).
|
||||
|
||||
|
||||
extensions(Prototypes) :-
|
||||
self(Self),
|
||||
findall(Prototype, extends_object(Prototype, Self), Prototypes).
|
||||
|
||||
|
||||
leaf(Leaf) :-
|
||||
self(Self),
|
||||
leaf(Self, Leaf).
|
||||
|
||||
|
||||
leaf(Self, Leaf) :-
|
||||
extends_object(Leaf, Self),
|
||||
\+ extends_object(_, Leaf).
|
||||
|
||||
leaf(Self, Leaf) :-
|
||||
extends_object(Object, Self),
|
||||
leaf(Object, Leaf).
|
||||
|
||||
|
||||
leaves(Leaves) :-
|
||||
self(Self),
|
||||
( setof(Leaf, leaf(Self, Leaf), Leaves) ->
|
||||
@@ -69,24 +56,19 @@
|
||||
; Leaves = []
|
||||
).
|
||||
|
||||
|
||||
descendant(Descendant) :-
|
||||
self(Self),
|
||||
descendant(Self, Descendant).
|
||||
|
||||
|
||||
descendant(Self, Descendant) :-
|
||||
extends_object(Descendant, Self).
|
||||
|
||||
descendant(Self, Descendant) :-
|
||||
extends_object(Descendant, Self),
|
||||
\+ extends_object(Descendant, Self).
|
||||
|
||||
descendant(Self, Descendant) :-
|
||||
extends_object(Subclass, Self),
|
||||
descendant(Subclass, Descendant).
|
||||
|
||||
|
||||
descendants(Descendants) :-
|
||||
self(Self),
|
||||
( setof(Descendant, descendant(Self, Descendant), Descendants) ->
|
||||
@@ -94,5 +76,4 @@
|
||||
; Descendants = []
|
||||
).
|
||||
|
||||
|
||||
:- end_category.
|
||||
|
@@ -3,14 +3,12 @@
|
||||
implements(queuep),
|
||||
extends(compound)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Queue predicates implemented using difference lists.']).
|
||||
|
||||
|
||||
as_list(Queue-Back, List) :-
|
||||
Queue == Back ->
|
||||
List = []
|
||||
@@ -19,70 +17,53 @@
|
||||
Queue = [Head| Rest],
|
||||
as_list(Rest-Back, Tail).
|
||||
|
||||
|
||||
empty(Front-Back) :-
|
||||
Front == Back.
|
||||
|
||||
|
||||
head(Front-Back, Head) :-
|
||||
Front \== Back,
|
||||
Front = [Head| _].
|
||||
|
||||
|
||||
join(Element, Front-[Element| Back], Front-Back).
|
||||
|
||||
|
||||
join_all([], Queue, Queue).
|
||||
|
||||
join_all([Head| Tail], Queue1, Queue3) :-
|
||||
join(Head, Queue1, Queue2),
|
||||
join_all(Tail, Queue2, Queue3).
|
||||
|
||||
|
||||
jump(Element, Front-Back, [Element| Front]-Back).
|
||||
|
||||
|
||||
jump_all([], Queue, Queue).
|
||||
|
||||
jump_all([Head| Tail], Queue1, Queue3) :-
|
||||
jump(Head, Queue1, Queue2),
|
||||
jump_all(Tail, Queue2, Queue3).
|
||||
|
||||
|
||||
length(Front-Back, Length) :-
|
||||
length(Front, Back, 0, N),
|
||||
Length = N.
|
||||
|
||||
|
||||
length(Front, Back, N, N) :-
|
||||
Front == Back, !.
|
||||
|
||||
length([_|Front], Back, K, N) :-
|
||||
L is K+1,
|
||||
length(Front, Back, L, N).
|
||||
|
||||
|
||||
new(Back-Back).
|
||||
|
||||
|
||||
serve(OldFront-Back, Head, NewFront-Back) :-
|
||||
OldFront \== Back,
|
||||
OldFront = [Head| NewFront].
|
||||
|
||||
|
||||
valid(Queue) :-
|
||||
nonvar(Queue),
|
||||
valid2(Queue).
|
||||
|
||||
|
||||
valid2(Queue-Back) :-
|
||||
Queue == Back,
|
||||
!.
|
||||
|
||||
valid2(Queue-Back) :-
|
||||
nonvar(Queue),
|
||||
Queue = [_| Tail],
|
||||
valid2(Tail-Back).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,93 +1,64 @@
|
||||
|
||||
:- protocol(queuep).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Queue protocol.']).
|
||||
|
||||
|
||||
:- public(empty/1).
|
||||
|
||||
:- mode(empty(@queue), zero_or_one).
|
||||
|
||||
:- info(empty/1, [
|
||||
comment is 'True if the queue is empty.',
|
||||
argnames is ['Queue']]).
|
||||
|
||||
|
||||
:- public(head/2).
|
||||
|
||||
:- mode(head(+queue, ?term), zero_or_one).
|
||||
|
||||
:- info(head/2, [
|
||||
comment is 'Unifies Head with the first element of the queue.',
|
||||
argnames is ['Queue', 'Head']]).
|
||||
|
||||
|
||||
:- public(join/3).
|
||||
|
||||
:- mode(join(@term, +queue, -queue), zero_or_one).
|
||||
|
||||
:- info(join/3, [
|
||||
comment is 'Adds the new element at the end of the queue.',
|
||||
argnames is ['Element', 'Queue_in', 'Queue_out']]).
|
||||
|
||||
|
||||
:- public(join_all/3).
|
||||
|
||||
:- mode(join_all(+list, +queue, -queue), zero_or_one).
|
||||
|
||||
:- info(join_all/3, [
|
||||
comment is 'Adds the new elements at the end of the queue. The elements are added in the same order that they appear in the list.',
|
||||
argnames is ['List', 'Queue_in', 'Queue_out']]).
|
||||
|
||||
|
||||
:- public(jump/3).
|
||||
|
||||
:- mode(jump(@term, +queue, -queue), zero_or_one).
|
||||
|
||||
:- info(jump/3, [
|
||||
comment is 'Adds the new element at the front of the queue.',
|
||||
argnames is ['Element', 'Queue_in', 'Queue_out']]).
|
||||
|
||||
|
||||
:- public(jump_all/3).
|
||||
|
||||
:- mode(jump_all(+list, +queue, -queue), zero_or_one).
|
||||
|
||||
:- info(jump_all/3, [
|
||||
comment is 'Adds the new elements at the front of the queue. The elements are added in the same order that they appear in the list.',
|
||||
argnames is ['Element', 'Queue_in', 'Queue_out']]).
|
||||
|
||||
|
||||
:- public(length/2).
|
||||
|
||||
:- mode(length(+queue, ?integer), zero_or_one).
|
||||
|
||||
:- info(length/2,
|
||||
[comment is 'Queue length.',
|
||||
argnames is ['Queue', 'Length']]).
|
||||
|
||||
|
||||
:- public(serve/3).
|
||||
|
||||
:- mode(serve(+queue, ?term, -queue), zero_or_one).
|
||||
|
||||
:- info(serve/3, [
|
||||
comment is 'Removes the first element of the queue for service.',
|
||||
argnames is ['Queue_in', 'Head', 'Queue_out']]).
|
||||
|
||||
|
||||
:- public(as_list/2).
|
||||
|
||||
:- mode(as_list(+queue, -list), one).
|
||||
|
||||
:- info(as_list/2,
|
||||
[comment is 'Converts a queue to a list.',
|
||||
argnames is ['Queue', 'List']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this library load the random_loader.lgt utility
|
||||
|
@@ -1,3 +1,3 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([randomp, random])).
|
||||
logtalk_load([randomp, random], [reload(skip)])).
|
||||
|
@@ -1,68 +1,48 @@
|
||||
|
||||
:- protocol(randomp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Random number generator protocol.']).
|
||||
|
||||
|
||||
:- public(random/1).
|
||||
|
||||
:- mode(random(-float), one).
|
||||
|
||||
:- info(random/1, [
|
||||
comment is 'Returns a new random float value in the interval [0.0, 1.0[.',
|
||||
argnames is ['Random']]).
|
||||
|
||||
|
||||
:- public(random/3).
|
||||
|
||||
:- mode(random(+integer, +integer, -integer), zero_or_one).
|
||||
:- mode(random(+float, +float, -float), zero_or_one).
|
||||
|
||||
:- info(random/3, [
|
||||
comment is 'Returns a new random value in the interval [Lower, Upper[.',
|
||||
argnames is ['Lower', 'Upper', 'Random']]).
|
||||
|
||||
|
||||
:- public(randseq/4).
|
||||
|
||||
:- mode(randseq(+integer, +integer, +integer, -list), zero_or_one).
|
||||
:- mode(randseq(+integer, +float, +float, -list), zero_or_one).
|
||||
|
||||
:- info(randseq/4, [
|
||||
comment is 'Returns a list of Length random values in the interval [Lower, Upper[.',
|
||||
argnames is ['Length', 'Lower', 'Upper', 'List']]).
|
||||
|
||||
|
||||
:- public(randset/4).
|
||||
|
||||
:- mode(randset(+integer, +integer, +integer, -list), zero_or_one).
|
||||
:- mode(randset(+integer, +float, +float, -list), zero_or_one).
|
||||
|
||||
:- info(randset/4, [
|
||||
comment is 'Returns an ordered set of Length random values in the interval [Lower, Upper[.',
|
||||
argnames is ['Length', 'Lower', 'Upper', 'Set']]).
|
||||
|
||||
|
||||
:- public(reset_seed/0).
|
||||
|
||||
:- mode(reset_seed, one).
|
||||
|
||||
:- info(reset_seed/0, [
|
||||
comment is 'Resets the random seed to its default value.']).
|
||||
|
||||
|
||||
:- public(set_seed/1).
|
||||
|
||||
:- mode(set_seed(+integer), zero_or_one).
|
||||
|
||||
:- info(set_seed/1, [
|
||||
comment is 'Sets the random seed to the given value.',
|
||||
argnames is ['Seed']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -3,89 +3,65 @@
|
||||
implements(setp),
|
||||
extends(compound)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Set predicates implemented using ordered lists. Uses ==/2 for element comparison and standard term ordering.']).
|
||||
|
||||
|
||||
delete([], _, []).
|
||||
|
||||
delete([Head| Tail], Element, Remaining) :-
|
||||
compare(Order, Head, Element),
|
||||
delete(Order, Head, Tail, Element, Remaining).
|
||||
|
||||
delete(=, _, Tail, _, Tail).
|
||||
|
||||
delete(<, Head, Tail, Element, [Head| Tail2]) :-
|
||||
delete(Tail, Element, Tail2).
|
||||
|
||||
delete(>, _, Tail, _, Tail).
|
||||
|
||||
|
||||
disjoint([], _) :- !.
|
||||
|
||||
disjoint(_, []) :- !.
|
||||
|
||||
disjoint([Head1| Tail1], [Head2| Tail2]) :-
|
||||
compare(Order, Head1, Head2),
|
||||
disjoint(Order, Head1, Tail1, Head2, Tail2).
|
||||
|
||||
|
||||
disjoint(<, _, Tail1, Head2, Tail2) :-
|
||||
disjoint(Tail1, [Head2| Tail2]).
|
||||
|
||||
disjoint(>, Head1, Tail1, _, Tail2) :-
|
||||
disjoint([Head1| Tail1], Tail2).
|
||||
|
||||
|
||||
equal(Set1, Set2) :-
|
||||
Set1 == Set2.
|
||||
|
||||
|
||||
empty(Set) :-
|
||||
Set == [].
|
||||
|
||||
|
||||
insert([], Element, [Element]).
|
||||
|
||||
insert([Head| Tail], Element, Set) :-
|
||||
compare(Order, Head, Element),
|
||||
insert(Order, Head, Tail, Element, Set).
|
||||
|
||||
|
||||
insert(<, Head, Tail, Element, [Head| Set]) :-
|
||||
insert(Tail, Element, Set).
|
||||
|
||||
insert(=, Head, Tail, _, [Head| Tail]).
|
||||
|
||||
insert(>, Head, Tail, Element, [Element, Head| Tail]).
|
||||
|
||||
|
||||
insert_all([], Set, Set).
|
||||
|
||||
insert_all([Head| Tail], Set1, Set3) :-
|
||||
insert(Set1, Head, Set2),
|
||||
insert_all(Tail, Set2, Set3).
|
||||
|
||||
|
||||
intersect([Head1| Tail1], [Head2| Tail2]) :-
|
||||
compare(Order, Head1, Head2),
|
||||
intersect(Order, Head1, Tail1, Head2, Tail2).
|
||||
|
||||
intersect(=, _, _, _, _).
|
||||
|
||||
intersect(<, _, Tail1, Head2, Tail2) :-
|
||||
intersect(Tail1, [Head2| Tail2]).
|
||||
|
||||
intersect(>, Head1, Tail1, _, Tail2) :-
|
||||
intersect([Head1| Tail1], Tail2).
|
||||
|
||||
|
||||
intersection(_, [], []) :- !.
|
||||
|
||||
intersection([], _, []) :- !.
|
||||
|
||||
intersection([Head1| Tail1], [Head2| Tail2], Intersection) :-
|
||||
@@ -94,170 +70,124 @@
|
||||
|
||||
intersection(=, Head, Tail1, _, Tail2, [Head| Intersection]) :-
|
||||
intersection(Tail1, Tail2, Intersection).
|
||||
|
||||
intersection(<, _, Tail1, Head2, Tail2, Intersection) :-
|
||||
intersection(Tail1, [Head2| Tail2], Intersection).
|
||||
|
||||
intersection(>, Head1, Tail1, _, Tail2, Intersection) :-
|
||||
intersection([Head1|Tail1], Tail2, Intersection).
|
||||
|
||||
|
||||
length(Set, Length) :-
|
||||
length(Set, 0, Length).
|
||||
|
||||
|
||||
length([], Length, Length).
|
||||
|
||||
length([_| Set], Acc, Length) :-
|
||||
Acc2 is Acc + 1,
|
||||
length(Set, Acc2, Length).
|
||||
|
||||
|
||||
member(Element, Set) :-
|
||||
var(Element) ->
|
||||
( var(Element) ->
|
||||
member_var(Element, Set)
|
||||
;
|
||||
member_nonvar(Element, Set).
|
||||
|
||||
; member_nonvar(Element, Set)
|
||||
).
|
||||
|
||||
member_var(Element, [Element| _]).
|
||||
|
||||
member_var(Element, [_| Set]) :-
|
||||
member_var(Element, Set).
|
||||
|
||||
|
||||
member_nonvar(Element, [Head| Tail]):-
|
||||
compare(Order, Element, Head),
|
||||
member_nonvar(Order, Element, Tail).
|
||||
|
||||
member_nonvar(=, _, _).
|
||||
|
||||
member_nonvar(>, Element, [Head| Tail]) :-
|
||||
compare(Order, Element, Head),
|
||||
member_nonvar(Order, Element, Tail).
|
||||
|
||||
|
||||
new([]).
|
||||
|
||||
|
||||
powerset(Set, PowerSet):-
|
||||
reverse(Set, RSet),
|
||||
powerset_1(RSet, [[]], PowerSet).
|
||||
|
||||
|
||||
powerset_1([], PowerSet, PowerSet).
|
||||
|
||||
powerset_1([X| Xs], Yss0, Yss):-
|
||||
powerset_2(Yss0, X, Yss1),
|
||||
powerset_1(Xs, Yss1, Yss).
|
||||
|
||||
|
||||
powerset_2([], _, []).
|
||||
|
||||
powerset_2([Zs| Zss], X, [Zs, [X| Zs]| Yss]):-
|
||||
powerset_2(Zss, X, Yss).
|
||||
|
||||
|
||||
reverse(List, Reversed) :-
|
||||
reverse(List, [], Reversed).
|
||||
|
||||
|
||||
reverse([], Reversed, Reversed).
|
||||
|
||||
reverse([Head| Tail], List, Reversed) :-
|
||||
reverse(Tail, [Head| List], Reversed).
|
||||
|
||||
|
||||
select(Head, [Head| Tail], Tail).
|
||||
|
||||
select(Head, [Head2| Tail], [Head2| Tail2]) :-
|
||||
select(Head, Tail, Tail2).
|
||||
|
||||
|
||||
subset([], _) :- !.
|
||||
|
||||
subset([Head1| Tail1], [Head2| Tail2]) :-
|
||||
compare(Order, Head1, Head2),
|
||||
subset(Order, Head1, Tail1, Head2, Tail2).
|
||||
|
||||
|
||||
subset(=, _, Tail1, _, Tail2) :-
|
||||
subset(Tail1, Tail2).
|
||||
|
||||
subset(>, Head1, Tail1, _, Tail2) :-
|
||||
subset([Head1| Tail1], Tail2).
|
||||
|
||||
|
||||
subtract(Set, [], Set) :- !.
|
||||
|
||||
subtract([], _, []) :- !.
|
||||
|
||||
subtract([Head1| Tail1], [Head2| Tail2], Difference) :-
|
||||
compare(Order, Head1, Head2),
|
||||
subtract(Order, Head1, Tail1, Head2, Tail2, Difference).
|
||||
|
||||
|
||||
subtract(=, _, Tail1, _, Tail2, Difference) :-
|
||||
subtract(Tail1, Tail2, Difference).
|
||||
|
||||
subtract(<, Head1, Tail1, Head2, Tail2, [Head1| Difference]) :-
|
||||
subtract(Tail1, [Head2| Tail2], Difference).
|
||||
|
||||
subtract(>, Head1, Tail1, _, Tail2, Difference) :-
|
||||
subtract([Head1| Tail1], Tail2, Difference).
|
||||
|
||||
|
||||
symdiff(Set, [], Set) :- !.
|
||||
|
||||
symdiff([], Set, Set) :- !.
|
||||
|
||||
symdiff([Head1| Tail1], [Head2| Tail2], Difference) :-
|
||||
compare(Order, Head1, Head2),
|
||||
symdiff(Order, Head1, Tail1, Head2, Tail2, Difference).
|
||||
|
||||
|
||||
symdiff(=, _, Tail1, _, Tail2, Difference) :-
|
||||
symdiff(Tail1, Tail2, Difference).
|
||||
|
||||
symdiff(<, Head1, Tail1, Head2, Tail2, [Head1| Difference]) :-
|
||||
symdiff(Tail1, [Head2| Tail2], Difference).
|
||||
|
||||
symdiff(>, Head1, Tail1, Head2, Tail2, [Head2| Difference]) :-
|
||||
symdiff([Head1| Tail1], Tail2, Difference).
|
||||
|
||||
|
||||
union(Set, [], Set) :- !.
|
||||
|
||||
union([], Set, Set) :- !.
|
||||
|
||||
union([Head1| Tail1], [Head2| Tail2], Union) :-
|
||||
compare(Order, Head1, Head2),
|
||||
union(Order, Head1, Tail1, Head2, Tail2, Union).
|
||||
|
||||
|
||||
union(=, Head, Tail1, _, Tail2, [Head| Union]) :-
|
||||
union(Tail1, Tail2, Union).
|
||||
|
||||
union(<, Head1, Tail1, Head2, Tail2, [Head1| Union]) :-
|
||||
union(Tail1, [Head2| Tail2], Union).
|
||||
|
||||
union(>, Head1, Tail1, Head2, Tail2, [Head2| Union]) :-
|
||||
union([Head1| Tail1], Tail2, Union).
|
||||
|
||||
|
||||
valid(Set) :-
|
||||
nonvar(Set),
|
||||
valid2(Set).
|
||||
|
||||
valid2([]) :-
|
||||
!.
|
||||
|
||||
valid2([_]) :-
|
||||
!.
|
||||
|
||||
valid2([Element1, Element2| Set]) :-
|
||||
Element1 @< Element2,
|
||||
valid2([Element2| Set]).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,157 +1,107 @@
|
||||
|
||||
:- protocol(setp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Set protocol.']).
|
||||
|
||||
|
||||
:- public(delete/3).
|
||||
|
||||
:- mode(delete(+set, @term, ?set), one).
|
||||
|
||||
:- info(delete/3,
|
||||
[comment is 'Deletes an element from a set returning the set of remaining elements.',
|
||||
argnames is ['Set', 'Element', 'Remaining']]).
|
||||
|
||||
|
||||
:- public(disjoint/2).
|
||||
|
||||
:- mode(disjoint(+set, +set), zero_or_one).
|
||||
|
||||
:- info(disjoint/2, [
|
||||
comment is 'True if the two sets have no element in common.',
|
||||
argnames is ['Set1', 'Set2']]).
|
||||
|
||||
|
||||
:- public(equal/2).
|
||||
|
||||
:- mode(equal(+set, +set), zero_or_one).
|
||||
|
||||
:- info(equal/2, [
|
||||
comment is 'True if the two sets are equal.',
|
||||
argnames is ['Set1', 'Set2']]).
|
||||
|
||||
|
||||
:- public(empty/1).
|
||||
|
||||
:- mode(empty(+set), zero_or_one).
|
||||
|
||||
:- info(empty/1, [
|
||||
comment is 'True if the set is empty.',
|
||||
argnames is ['Set']]).
|
||||
|
||||
|
||||
:- public(insert/3).
|
||||
|
||||
:- mode(insert(+set, +term, ?set), one).
|
||||
|
||||
:- info(insert/3, [
|
||||
comment is 'Inserts an element in a set, returning the resulting set.',
|
||||
argnames is ['In', 'Element', 'Out']]).
|
||||
|
||||
|
||||
:- public(insert_all/3).
|
||||
|
||||
:- mode(insert_all(+list, +set, ?set), one).
|
||||
|
||||
:- info(insert_all/3, [
|
||||
comment is 'Inserts a list of elemnts in a set, returning the resulting set.',
|
||||
argnames is ['List', 'In', 'Out']]).
|
||||
|
||||
|
||||
:- public(intersect/2).
|
||||
|
||||
:- mode(intersect(+set, +set), zero_or_one).
|
||||
|
||||
:- info(intersect/2, [
|
||||
comment is 'True if the two sets have at least one element in common.',
|
||||
argnames is ['Set1', 'Set2']]).
|
||||
|
||||
|
||||
:- public(intersection/3).
|
||||
|
||||
:- mode(intersection(+set, +set, ?set), zero_or_one).
|
||||
|
||||
:- info(intersection/3, [
|
||||
comment is 'Returns the intersection of Set1 and Set2.',
|
||||
argnames is ['Set1', 'Set2', 'Intersection']]).
|
||||
|
||||
|
||||
:- public(length/2).
|
||||
|
||||
:- mode(length(+set, ?integer), zero_or_one).
|
||||
|
||||
:- info(length/2,
|
||||
[comment is 'Number of set elements.',
|
||||
argnames is ['Set', 'Length']]).
|
||||
|
||||
|
||||
:- public(member/2).
|
||||
|
||||
:- mode(member(+term, +set), zero_or_one).
|
||||
:- mode(member(-term, +set), zero_or_more).
|
||||
|
||||
:- info(member/2,
|
||||
[comment is 'Element is a member of set Set.',
|
||||
argnames is ['Element', 'Set']]).
|
||||
|
||||
|
||||
:- public(powerset/2).
|
||||
|
||||
:- mode(powerset(+set, -list), one).
|
||||
|
||||
:- info(powerset/2,
|
||||
[comment is 'Returns the power set of a set, represented as a list of sets.',
|
||||
argnames is ['Set', 'Powerset']]).
|
||||
|
||||
|
||||
:- public(select/3).
|
||||
|
||||
:- mode(select(?term, +set, ?set), zero_or_more).
|
||||
|
||||
:- info(select/3,
|
||||
[comment is 'Selects an element from a set, returning the set of remaining elements.',
|
||||
argnames is ['Element', 'Set', 'Remaining']]).
|
||||
|
||||
|
||||
:- public(subset/2).
|
||||
|
||||
:- mode(subset(+set, +set), zero_or_one).
|
||||
|
||||
:- info(subset/2, [
|
||||
comment is 'True if Subset is a subset of Set.',
|
||||
argnames is ['Subset', 'Set']]).
|
||||
|
||||
|
||||
:- public(subtract/3).
|
||||
|
||||
:- mode(subtract(+set, +set, ?set), zero_or_one).
|
||||
|
||||
:- info(subtract/3, [
|
||||
comment is 'True when Difference contains all and only the elements of Set1 which are not also in Set2.',
|
||||
argnames is ['Set1', 'Set2', 'Difference']]).
|
||||
|
||||
|
||||
:- public(symdiff/3).
|
||||
|
||||
:- mode(symdiff(+set, +set, ?set), zero_or_one).
|
||||
|
||||
:- info(symdiff/3, [
|
||||
comment is 'True if Difference is the symmetric difference of Set1 and Set2.',
|
||||
argnames is ['Set1', 'Set2', 'Difference']]).
|
||||
|
||||
|
||||
:- public(union/3).
|
||||
|
||||
:- mode(union(+set, +set, ?set), zero_or_one).
|
||||
|
||||
:- info(union/3, [
|
||||
comment is 'True if Union is the union of Set1 and Set2.',
|
||||
argnames is ['Set1', 'Set2', 'Union']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,23 +2,45 @@
|
||||
:- object(term,
|
||||
implements(termp)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Prolog term predicates.']).
|
||||
date is 2007/4/3,
|
||||
comment is 'Prolog term utility predicates.']).
|
||||
|
||||
depth(Term, Depth) :-
|
||||
depth(Term, 0, 0, Depth).
|
||||
|
||||
depth(Var, Acc, MaxSoFar, Depth) :-
|
||||
var(Var),
|
||||
!,
|
||||
( Acc > MaxSoFar ->
|
||||
Depth = Acc
|
||||
; Depth = MaxSoFar
|
||||
).
|
||||
depth(Atomic, Acc, MaxSoFar, Depth) :-
|
||||
atomic(Atomic),
|
||||
!,
|
||||
( Acc > MaxSoFar ->
|
||||
Depth = Acc
|
||||
; Depth = MaxSoFar
|
||||
).
|
||||
depth([Arg| Args], Acc, MaxSoFar, Depth) :-
|
||||
!,
|
||||
depth(Arg, Acc, MaxSoFar, ArgDepth),
|
||||
depth(Args, Acc, ArgDepth, Depth).
|
||||
depth(Term, Acc, MaxSoFar, Depth) :-
|
||||
Acc2 is Acc + 1,
|
||||
Term =.. [_| Args],
|
||||
depth(Args, Acc2, MaxSoFar, Depth).
|
||||
|
||||
ground(Term) :-
|
||||
nonvar(Term),
|
||||
functor(Term, _, Arity),
|
||||
ground(Arity, Term).
|
||||
|
||||
|
||||
ground(0, _) :-
|
||||
!.
|
||||
|
||||
ground(N, Term) :-
|
||||
N > 0,
|
||||
arg(N, Term, Arg),
|
||||
@@ -26,39 +48,34 @@
|
||||
N2 is N - 1,
|
||||
ground(N2, Term).
|
||||
|
||||
|
||||
occurs(Var, Term) :-
|
||||
var(Term) ->
|
||||
( var(Term) ->
|
||||
Var == Term
|
||||
;
|
||||
functor(Term, _, Arity),
|
||||
occurs(Arity, Var, Term).
|
||||
|
||||
; functor(Term, _, Arity),
|
||||
occurs(Arity, Var, Term)
|
||||
).
|
||||
|
||||
occurs(N, Var, Term) :-
|
||||
compound(Term),
|
||||
arg(N, Term, Arg),
|
||||
occurs(Var, Arg),
|
||||
!.
|
||||
|
||||
occurs(N, Var, Term) :-
|
||||
N > 1,
|
||||
N2 is N - 1,
|
||||
occurs(N2, Var, Term).
|
||||
|
||||
|
||||
subsumes(General, Specific) :-
|
||||
vars(Specific, Vars),
|
||||
subsumes(General, Specific, Vars).
|
||||
|
||||
|
||||
subsumes(General, Specific, Vars) :-
|
||||
var(General),
|
||||
!,
|
||||
(var_member_chk(General, Vars) ->
|
||||
( var_member_chk(General, Vars) ->
|
||||
General == Specific
|
||||
;
|
||||
General = Specific).
|
||||
; General = Specific
|
||||
).
|
||||
|
||||
subsumes(General, Specific, Vars) :-
|
||||
nonvar(Specific),
|
||||
@@ -66,9 +83,8 @@
|
||||
functor(Specific, Functor, Arity),
|
||||
subsumes(Arity, General, Specific, Vars).
|
||||
|
||||
|
||||
subsumes(0, _, _, _) :- !.
|
||||
|
||||
subsumes(0, _, _, _) :-
|
||||
!.
|
||||
subsumes(N, General, Specific, Vars) :-
|
||||
arg(N, General, GenArg),
|
||||
arg(N, Specific, SpeArg),
|
||||
@@ -76,56 +92,49 @@
|
||||
M is N-1, !,
|
||||
subsumes(M, General, Specific, Vars).
|
||||
|
||||
|
||||
var_member_chk(Var, [Head| Tail]) :-
|
||||
Var == Head ->
|
||||
( Var == Head ->
|
||||
true
|
||||
;
|
||||
var_member_chk(Var, Tail).
|
||||
|
||||
; var_member_chk(Var, Tail)
|
||||
).
|
||||
|
||||
subterm(Term, Term).
|
||||
|
||||
subterm(Sub, Term) :-
|
||||
nonvar(Term),
|
||||
functor(Term, _, N),
|
||||
subterm(N, Sub, Term).
|
||||
|
||||
|
||||
subterm(N, Sub, Term) :-
|
||||
compound(Term),
|
||||
arg(N, Term, Arg),
|
||||
subterm(Sub, Arg).
|
||||
|
||||
subterm(N, Sub, Term) :-
|
||||
N > 1,
|
||||
M is N-1,
|
||||
subterm(M, Sub, Term).
|
||||
|
||||
|
||||
valid(_).
|
||||
|
||||
variant(Term1, Term2) :-
|
||||
\+ \+ subsumes(Term1, Term2),
|
||||
\+ \+ subsumes(Term2, Term1).
|
||||
|
||||
vars(Term, Vars) :-
|
||||
vars(Term, [], Vars).
|
||||
|
||||
|
||||
vars(Term, Acc, Vars) :-
|
||||
var(Term) ->
|
||||
(var_member_chk(Term, Acc) ->
|
||||
( var(Term) ->
|
||||
( var_member_chk(Term, Acc) ->
|
||||
Vars = Acc
|
||||
;
|
||||
Vars = [Term| Acc])
|
||||
;
|
||||
Term =.. [_| Args],
|
||||
var_list(Args, Acc, Vars).
|
||||
|
||||
; Vars = [Term| Acc]
|
||||
)
|
||||
; Term =.. [_| Args],
|
||||
var_list(Args, Acc, Vars)
|
||||
).
|
||||
|
||||
var_list([], Vars, Vars).
|
||||
|
||||
var_list([Term| Terms], Acc, Vars) :-
|
||||
vars(Term, Acc, Acc2),
|
||||
var_list(Terms, Acc2, Vars).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,75 +1,64 @@
|
||||
|
||||
:- protocol(termp).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
version is 1.1,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Prolog terms protocol.']).
|
||||
date is 2007/4/3,
|
||||
comment is 'Prolog term utility predicates protocol.']).
|
||||
|
||||
:- public(depth/2).
|
||||
:- mode(depth(@term, ?integer), zero_or_one).
|
||||
:- info(depth/2, [
|
||||
comment is 'True if the depth of Term is Depth. The depth of atomic terms is zero; the depth of a compound term is one plus the maximium depth of its sub-terms.',
|
||||
argnames is ['Term', 'Depth']]).
|
||||
|
||||
:- public(ground/1).
|
||||
|
||||
:- mode(ground(@term), zero_or_one).
|
||||
|
||||
:- info(ground/1, [
|
||||
comment is 'True if the argument is ground.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(new/1).
|
||||
|
||||
:- mode(new(-nonvar), zero_or_one).
|
||||
|
||||
:- info(new/1, [
|
||||
comment is 'Creates a new term instance (if meaningful).',
|
||||
argnames is ['Term']]).
|
||||
|
||||
|
||||
:- public(occurs/2).
|
||||
|
||||
:- mode(occurs(@var, @term), zero_or_one).
|
||||
|
||||
:- info(occurs/2, [
|
||||
comment is 'True if the variable occurs in the term.',
|
||||
argnames is ['Variable', 'Term']]).
|
||||
|
||||
|
||||
:- public(subsumes/2).
|
||||
|
||||
:- mode(subsumes(@term, @term), zero_or_one).
|
||||
|
||||
:- info(subsumes/2, [
|
||||
comment is 'The first term subsumes the second term.',
|
||||
argnames is ['General', 'Specific']]).
|
||||
|
||||
|
||||
:- public(subterm/2).
|
||||
|
||||
:- mode(subterm(?term, +term), zero_or_more).
|
||||
|
||||
:- info(subterm/2, [
|
||||
comment is 'The first term is a subterm of the second term.',
|
||||
argnames is ['Subterm', 'Term']]).
|
||||
|
||||
|
||||
:- public(valid/1).
|
||||
|
||||
:- mode(valid(@nonvar), zero_or_one).
|
||||
|
||||
:- info(valid/1, [
|
||||
comment is 'Term is valid.',
|
||||
argnames is ['Term']]).
|
||||
|
||||
:- public(variant/2).
|
||||
:- mode(variant(@term, @term), zero_or_one).
|
||||
:- info(variant/2, [
|
||||
comment is 'Each term is a variant of the other (i.e. they are structurally equivalent).',
|
||||
argnames is ['Term1', 'Term2']]).
|
||||
|
||||
:- public(vars/2).
|
||||
|
||||
:- mode(vars(@term, -list), one).
|
||||
|
||||
:- info(vars/2, [
|
||||
comment is 'Returns a list of all term variables.',
|
||||
argnames is ['Term', 'List']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -2,26 +2,21 @@
|
||||
:- object(time,
|
||||
implements(timep)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Time predicates.']).
|
||||
|
||||
|
||||
now(Hours, Mins, Secs) :-
|
||||
{'$lgt_current_time'(Hours, Mins, Secs)}.
|
||||
|
||||
|
||||
cpu_time(Seconds) :-
|
||||
{'$lgt_cpu_time'(Seconds)}.
|
||||
|
||||
|
||||
valid(Hours, Mins, Secs) :-
|
||||
integer(Hours), Hours >= 0,
|
||||
integer(Mins), Mins >= 0, Mins =< 59,
|
||||
integer(Secs), Secs >= 0, Secs =< 59.
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -1,39 +1,28 @@
|
||||
|
||||
:- protocol(timep).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'Time protocol.']).
|
||||
|
||||
|
||||
:- public(now/3).
|
||||
|
||||
:- mode(now(-integer, -integer, -integer), one).
|
||||
|
||||
:- info(now/3, [
|
||||
comment is 'Returns current time.',
|
||||
argnames is ['Hours', 'Mins', 'Secs']]).
|
||||
|
||||
|
||||
:- public(cpu_time/1).
|
||||
|
||||
:- mode(cpu_time(-number), one).
|
||||
|
||||
:- info(cpu_time/1,
|
||||
[comment is 'Returns the current cpu time.',
|
||||
argnames is ['Time']]).
|
||||
|
||||
|
||||
:- public(valid/3).
|
||||
|
||||
:- mode(valid(+integer, +integer, +integer), zero_or_one).
|
||||
|
||||
:- info(valid/3, [
|
||||
comment is 'True if the arguments represent a valid time value.',
|
||||
argnames is ['Hours', 'Mins', 'Secs']]).
|
||||
|
||||
|
||||
:- end_protocol.
|
||||
|
@@ -1,9 +1,9 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.29.5
|
||||
================================================================
|
||||
Logtalk - Open source object-oriented logic programming language
|
||||
Release 2.30.1
|
||||
|
||||
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
================================================================
|
||||
|
||||
|
||||
To load all entities in this group load the types_loader.lgt utility
|
||||
|
@@ -13,4 +13,4 @@
|
||||
queuep, queue,
|
||||
dictionaryp, bintree,
|
||||
setp, set, set1,
|
||||
comparingp])).
|
||||
comparingp], [reload(skip)])).
|
||||
|
@@ -2,45 +2,36 @@
|
||||
:- object(varlist,
|
||||
extends(list)).
|
||||
|
||||
|
||||
:- info([
|
||||
version is 1.0,
|
||||
author is 'Paulo Moura',
|
||||
date is 2000/7/24,
|
||||
comment is 'List of variables predicates.']).
|
||||
|
||||
|
||||
member(Element, [Head| _]) :-
|
||||
Element == Head.
|
||||
|
||||
member(Element, [_| Tail]) :-
|
||||
member(Element, Tail).
|
||||
|
||||
|
||||
memberchk(Element, [Head| Tail]) :-
|
||||
Element == Head ->
|
||||
( Element == Head ->
|
||||
true
|
||||
;
|
||||
memberchk(Element, Tail).
|
||||
|
||||
; memberchk(Element, Tail)
|
||||
).
|
||||
|
||||
prefix([], _).
|
||||
|
||||
prefix([Head1| Tail1], [Head2| Tail2]) :-
|
||||
Head1 == Head2,
|
||||
prefix(Tail1, Tail2).
|
||||
|
||||
|
||||
valid(List) :-
|
||||
nonvar(List),
|
||||
\+ \+ valid2(List).
|
||||
|
||||
|
||||
valid2([]).
|
||||
|
||||
valid2([Head| Tail]) :-
|
||||
var(Head),
|
||||
valid2(Tail).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
Reference in New Issue
Block a user