home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
aijournl
/
ai_oct86.arc
/
OBJECT2.LTG
< prev
next >
Wrap
Text File
|
1986-07-18
|
2KB
|
59 lines
Listing 2
áááááááááááááááááááááááááááá
Improvements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ì
% to avoid the problem of "failure to unify in the head", this alternativeì
% version of "send" always selects an method without regard to the parametersì
% of the target object or of the message
send(Object,Message) :-ì
ááááááááMessage =.. [Predicate | Args],ì
áááááááálength(Args,MsgArity),ì
ááááááááGoalArity is MsgArity + 1,ì
ááááááááfunctor(Goal,Predicate,GoalArity), % Goal with uninst argsì
ááááááááarg(1,Goal,Skeleton),ì
ááááááááisa_chain(Object,Object1),ì
áááááááámgt(Object1,Skeleton), % Skeleton is Object1 w/ uninst argsì
ááááááááclause(Goal,Body) -> % commit to override dup methodsì
ááááááááGoal =.. [Predicate,Object1|Args], % instantiate args of Goalì
ááááááááBody.
% "mgt" stands for "most general term"ì
mgt(Term,Skeleton) :-ì
áááááááánonvar(Term) ->ì
ááááááááfunctor(Term,Functor,Arity), functor(Skeleton,Functor,Arity) ;ì
ááááááááTerm = Skeleton.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ì
% to get breadth-first, left-to-right selection of methods from ancestorsè
isa_chain(Object,Object). % try Object itself firstì
isa_chain(Object,Ancestor) :-ì
ááááááááprevious_generations([Object],Ancestor).
previous_generations([obj],_) :- !, fail. % the root has no parentsì
previous_generations(Objects,Ancestor) :-ì
ááááááááparents(Objects,Parents),ì
áááááááá\+ Parents = [],ì
áááááááá( member(Ancestor,Parents)ì
áááááááá; previous_generations(Parents, Ancestor)ì
áááááááá).
parents([],[]).ì
parents([Object|Rest],AllParents) :-ì
áááááááábagof0(Parent,Object^isa(Object,Parent),Parents),ì
ááááááááparents(Rest,RestParents),ì
ááááááááappend(Parents,RestParents,AllParents).
% like standard builtin bagof, except Bag is [] when no solutionsì
bagof0(X,G,B) :-ì
áááááááábagof(X,G,B) -> true ; B = [].
member(X,[X|_]).ì
member(X,[_|L]) :- member(X,L).
append([],L,L).ì
append([H|L],M,[H|N]) :- append(L,M,N).