Subject: Re: setarg and backtracking

From: Jan Wielemaker <[email-masked]>
Date: Mon, 24 Jul 2000 16:09:30 +0200

On Mon, 24 Jul 2000, Rolf Socher wrote:
>Could it be that setarg/3 causes problems with backtracking? I call something
>like
> 	arg(N,Term,Value),
>	delete(Value,X,Value1),
>	setarg(N,Term,Value1)
>where Value is a list such as [1,2,3,4,5], and X is a number. When backtracking
>takes place on this branch, the variable Value has a value such as 
>	[1|_G150310]
>Can anybody help me with this problem?

Not sure what you try to do.  I think you misjudged the semantics of
delete/3.  I destilled the program below.

test(T, X) :-
	T = t([1,2,3,4,5]),
	test2(T, X).

test2(Term, X) :-
	arg(N,Term,Value),
	select(Value,X,Value1),
	setarg(N,Term,Value1).

Which produces:

?- test(L, X).

L = t([2, 3, 4, 5])
X = 1 ;

L = t([1, 3, 4, 5])
X = 2 ;

L = t([1, 2, 4, 5])
X = 3 ;

L = t([1, 2, 3, 5])
X = 4 ;

L = t([1, 2, 3, 4])
X = 5 ;

No

This looks ok to me.  If I'm wrong, please send a complete program so we
don't have to guess what you are doing.

	Regards --- Jan

P.s.	This is not advertisement for setarg/3, I think one should stay
	away from it whenever possible.  It is there mostly for
	compatibility reasons.