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

From: "Rinke Hoekstra" <[email-masked]>
Date: Fri, 7 Jan 2000 13:34:44 +0100

Absolutely right, my humble apologies.
This solves the problem, though:

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).

(still less steps 109 vs 131)

Groeten,

	Rinke

-----Original Message-----
From: Pascal Vaillant [mailto:[email-masked]]
Sent: vrijdag 7 januari 2000 13:11
To: Prolog Mailing List
Subject: RE: I am having trouble writing replace/4

> 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 == Replacant2,
> 	replace(HReplacant,HReplacer,Tail,NewTail).
> replace(HReplacant,HReplacer,[Head|Tail],[Head|NewTail]):-
> 	replace(HReplacant,HReplacer,Tail,NewTail).
>
> This algorithm takes less steps (trace it to find out).
>

Right, but it doesn't solve Doug's problem (he does not want
HReplacant [A in his version] to be unified with some element
of the Replacer list).

Groetjes,

Pascal

----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to [email-masked] using the Subject:
"unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/