The example below deals with personID's and sets of them. The personID's are implemented as of domain
symbol and the sets as of domain
personIdSet.
Domain
personIdSet in turn is implemented through a patricia set of unsignedNative keys (patricia set's code is just a modified version of the
radixTree package, the code is in package
radixSet in attached project "PredicateConstant").
I want to hide the way,
personIdSet is implemented, from the main code. So, in the main code I use predicates
personIdSet_insert,
personIdSet_union,
personIdSet_getAll_nd rather than anything from package
radixSet.
The issue now is, that one of the
personIdSet predicates, i.e.
personIdSet_union, happens to be completely equal to
radixSet::merge. Hence it would be nice to just give predicate
radixSet::merge a second name, which fits to the rest of the
personIdSet predicates.
Regards
Martin
Code: Select all
domains
personId = symbol.
%%%%%%%%%
% Domains and predicates for personIdSet
domains
personIdSet = radixSet::dictionary.
constants
personIdSet_empty : personIdSet = radixSet::empty.
class predicates
personIdSet_insert : (
personIdSet PersonIdSet_0,
personId PersonId)
-> personIdSet PersonIdSet.
clauses
personIdSet_insert(PersonIdSet_0, PersonId) = radixSet::insert(PersonIdSet_0, uncheckedConvert(unsignedNative, PersonId)).
class predicates
personIdSet_getAll_nd : (personIdSet PersonIdSet_0)
-> personId PersonId
nondeterm.
clauses
personIdSet_getAll_nd(PersonIdSet_0) = uncheckedConvert(personId, PersonIdUnsignedNative) :-
PersonIdUnsignedNative = radixSet::getAll_nd(PersonIdSet_0).
class facts %instead of a fact a predicate constant could go here
personIdSet_union : function{personIdSet PersonIdSetA, personIdSet PersonIdSetB, personIdSet PersonIdSetAB} := radixSet::merge.
%%%%%%%%%
% Main code
clauses
run() :-
PersonIdSet_a1 = personIdSet_insert(personIdSet_empty, "Huey"),
PersonIdSet_a = personIdSet_insert(PersonIdSet_a1, "Dewey"),
PersonIdSet_b1 = personIdSet_insert(personIdSet_empty, "Louie"),
PersonIdSet_b = personIdSet_insert(PersonIdSet_b1, "Huey"),
PersonIdSet_ab = personIdSet_union(PersonIdSet_a, PersonIdSet_b),
foreach PersonId = personIdSet_getAll_nd(PersonIdSet_ab) do
stdIo::write(PersonId, "\n")
end foreach.
You do not have the required permissions to view the files attached to this post.