Re: Meta-called do loops and setarg

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Thu 29 May 2003 02:23:27 PM GMT
Message-ID: <3ED617DF.EF5CE0CF@icparc.ic.ac.uk>
Hi Josh,

in brief, the solution is to remove setarg/3 from the language.
We can put this on the plan for a future release.

Unfortunately, it is very difficult to reconcile constant
demands for impure, low-level features with an aspiration
to keep the language semantics simple and clean.

When you use setarg/3, you destroy the referential transparency
property and simple notion of identity that you otherwise have
in logic programming (the man page for setarg/3 tries to say
that in its own clumsy ways).

In your example, this 'feature' of setarg/3 allows you to construct
a program that behaves differently, depending on the time (compile
vs call time) at which the loop is translated into its recursive
equivalent:

In query 1, the effective loop is, as written,

  (count(I, 1, 4), param(X) do setarg(1, X, I)

In query 2, X is already substituted, and the effective loop is

  (count(I, 1, 4), param(p(0, Y)) do setarg(1, p(0, Y), I))

which is equivalent to

  (count(I, 1, 4), param(Y) do setarg(1, p(0, Y), I)

and explains the observed behaviour.

Since setarg/3 breaks such a fundamental property, loops are surely
not the only context in which you can construct weird behaviours.
It is therefore quite important to limit and localise the use of
setarg/3 as much as possible, while we still support it.

Cheers,
--Joachim


josh singer wrote:
> 
> Hi folks,
> 
> Look at the following example, run on v 5.6 #28, Linux. With each iteration
> of the do loop the first param of X gets set to a higher number. Fine.
> 
> But if we meta-call the do loop, the setargs appear not to have any effect.
> Seems like a bug. The bug has been there at least since 5.4.
> 
> Wierdly, if you instantiate Y first, the bug goes away.
> 
> cheers,
> 
> josh
> 
> ----
> 
> ECLiPSe Constraint Logic Programming System [kernel]
> Copyright Imperial College London and ICL
> Certain libraries copyright Parc Technologies Ltd
> GMP library copyright Free Software Foundation
> Version 5.6 #28, Mon Apr 21 00:13 2003
> [eclipse 1]:  X = p(0, Y), (count(I, 1, 4), param(X) do setarg(1, X, I)).
> 
> Y = Y
> X = p(4, Y)
> I = I
> Yes (0.00s cpu)
> [eclipse 2]:  X = p(0, Y), call((count(I, 1, 4), param(X) do setarg(1, X,
> I))).
> 
> Y = Y
> X = p(0, Y)
> I = I
> Yes (0.00s cpu)
> [eclipse 3]:

-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
 Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Thu May 29 15:23:28 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:08:22 PM GMT GMT