Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!torn!news.bc.net!newsserver.sfu.ca!fornax!cs.sfu.ca!serge
From: serge@cs.sfu.ca (Serge Le Huitouze)
Subject: Re: setarg/3 (Was: speed of prolog)
In-Reply-To: kish@cs.man.ac.uk's message of 18 Jun 1995 02:32:52 GMT
Message-ID: <SERGE.95Jun19153749@maroilles.cs.sfu.ca>
Sender: news@cs.sfu.ca
Organization: School of Computing Science, Simon Fraser University
References: <THOMASL.95Jun13172908@arnold.csd.uu.se>
	<SERGE.95Jun16150840@maroilles.cs.sfu.ca>
	<KISH.95Jun18033252@rdf035.cs.man.ac.uk>
Date: 19 Jun 1995 22:37:49 GMT
Lines: 40


 > >% ?- T = f(X), setarg(1,T,33), R=result(T,X).
 > >%
 > >%T = f(33)
 > >%X = _28
 > >%R = result(f(33),_28)
 > >%yes
 > >% ?- [user].
 > >%foo(R) :- T = f(X), setarg(1,T,33), R=result(T,X).
 > >%^D
 > >%yes
 > >%| ?- foo(R).
 > >%
 > >%R = result(f(33),33)
 > >%yes
 >
 > Well, as far as I know, setarg/3 is a SICStus-specific predicate, and
 > I have verified the above with SICStus 2.1#9. This difference in
 > behaviour certainly seems to be a bug to me.
 >
 >
 > >The expected behavior is to change the first argument of T, not X !
 >
 > X *is* the first argument of T, so of course it should be bound to 33. 

                                                   ^^^^^^^^^^^^^^^

Setarg/3 sure doesn't *bind* any term. It is supposed to update (in a
backtrackable manner) a subterm of a given term.


 > Once you bound X to the first argument of T, they are (or should be) the
 > same entity.  

Now, let's take another example:
Instead of "T = f(X)", let's have "T = f(1)", or "T = f(g(X))".

Do you think that 33 should be the same entity as 1 or g(X), after the
call to 'setarg/3' ?

