From rhoekstr@wins.uva.nl  Fri Jan  7 13:27:28 2000
Received: from smtp2.a2000.nl (duck.a2000.nl [62.108.1.88])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id NAA06049
	for <prolog@swi.psy.uva.nl>; Fri, 7 Jan 2000 13:27:28 +0100 (MET)
Received: from node10e0e.a2000.nl ([24.132.14.14] helo=RHINO)
	by smtp2.a2000.nl with smtp (Exim 2.02 #4)
	id 126YUO-0003Bs-00
	for prolog@swi.psy.uva.nl; Fri, 7 Jan 2000 13:27:32 +0100
From: "Rinke Hoekstra" <rhoekstr@wins.uva.nl>
To: "Prolog Mailing List" <prolog@swi.psy.uva.nl>
Subject: RE: I am having trouble writing replace/4 
Date: Fri, 7 Jan 2000 13:34:44 +0100
Message-ID: <LFEJKFIDOJEOIHAFBNBFMEBCCCAA.rhoekstr@wins.uva.nl>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
In-Reply-To: <Pine.LNX.4.05.10001071209160.2036-100000@ppp196-103.rz.hu-berlin.de>
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600

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:Pascal.Vaillant@rz.hu-berlin.de]
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 prolog-request@swi.psy.uva.nl 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/


