Subject: RE: I am having trouble writing replace/4

From: "Douglas Miles (Volt Computer)" <[email-masked]>
Date: Fri, 7 Jan 2000 06:06:29 -0800

Thank you so we now have these they both work very well.  
The 2 are logically equivalent
I guess the difference in the *-> vs. separated clauses?

But both do what they are needed for :).. my original produced some real
funny results in a machine dissembler I am building.

I'll share the complete code for it when I am done, if you guys are
interested.
It basically takes 2 Lists of Machine Code (actually Lists of Anything) that
are logically similar.. It unifies them as much as it can.  Then presents
you with a difference between the lists.. It presents a few prolog rules
that would have been required in total unification and why from rules
learned before that the structures are possibly equivalent.

for example..
?-make_new_rule([my,dog,has,fleas],[my,cat,has,worms],Rule).

Rule=new_rule(
	from_to(MY,dog,HAS,fleas],[MY,cat,HAS,worms]),
	varlist(['MY'=my,'HAS'=has]),
	required_prolog((
		mem('MY',MY),
		mem('HAS',HAS)
		(related(dog,cat);related(cat,dog)),
		(related(fleas,worms);related(worms,fleas))
		)),
	asserted((mem('MY',my),mem('HAS',has)))
	protos([[dog,fleas],[cat,worms]]),
	final(
		rule([MY,_A,HAS,_B],[MY,_C,HAS,_D],
	
(mem('MY',MY),mem('HAS',HAS),related(_A,_B),related(_C,_D))
		)
	)

Well you can see the basic concept.. The lists are not of course always the
same length and there are going to be _several_ "required_prolog" outputs ..

related/2 is the last resort 'cheat' it will come up with.
mem/2 is all that can be 'known thru basic unification' or 'told to be true'

premuted/2, both_sibs/2, etc..

The goal is it will be fed similar lists until it has a basic rules set and
that it can be left to its own devices for future conversions.

Thanks again Pascal, Rinke and Marcos :) 	
	Douglas Miles [email-masked]

/*   Pascal Vaillant [mailto:[email-masked]] */

replaceList([],[],NothingToDo,NothingToDo).

replaceList([HeadBefore|TailBefore],[HeadAfter|TailAfter],Start,End) :-
  replace(HeadBefore,HeadAfter,Start,Middle),
  replaceList(TailBefore,TailAfter,Middle,End).

replace(_,_,[],[]).

replace(A,B,[C|L],[D|R]) :-
  ((A==C) *->
   D=B ;
   D=C),
  replace(A,B,L,R).

/*    Rinke Hoekstra [mailto:[email-masked]]  */

replace_list([],[],List,List).
replace_list([HReplacant|TReplacant],[HReplacer|TReplacer],List,NewList):-
 	replace(HReplacant,HReplacer,List,IList),
 	replace_list(TReplacant,TReplacer,IList,NewList).

replace(_,_,[],[]).
replace(HReplacant1,HReplacer,[HReplacant2|Tail],[HReplacer|NewTail]):-
	HReplacant1 == HReplacant2,
 	replace(HReplacant1,HReplacer,Tail,NewTail).
replace(HReplacant,HReplacer,[Head|Tail],[Head|NewTail]):-
 	replace(HReplacant,HReplacer,Tail,NewTail).

/*  And thank you as well Marcos :) [mailto:[email-masked]]   */

replaceList(_,_,[],[]):-!.
replaceList(L1,L2,[X|RestL],[X2|ResulL]):-!,
   replace(L1,L2,X,X2),
   replaceList(L1,L2,RestL,ResulL).

replace([], [], X, X).
replace([X|_], [X2|_], X, X2):-!.
replace([_|L], [_|L2], X, X2):-
	replace(L, L2, X, X2).