[m-rev.] State variable syntax transformation
Simon Taylor
stayl at cs.mu.OZ.AU
Thu Feb 21 16:40:43 AEDT 2002
On 07-Feb-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Index: reference_manual.texi
> ===================================================================
> + at table @code
> +
> + at item @var{Head} :- @var{Body}
> + at example
> +transform((@var{Head} :- @var{Body}), @var{X}, @var{ThisX}, @var{NextX}) =
> +substitute(@var{Head}, @var{X}, @var{ThisX}, @var{NextX}) :- transform(@var{Body}, @var{X}, @var{ThisX}, @var{NextX})
> + at end example
> +
> + at item @var{Head} --> @var{Body}
> + at example
> +transform((@var{Head} --> @var{Body}), @var{X}, @var{ThisX}, @var{NextX}) =
> +substitute(@var{Head}, @var{X}, @var{ThisX}, @var{NextX}) :- transform(@var{Body}, @var{X}, @var{ThisX}, @var{NextX})
> + at end example
s/:-/-->/ in the last line.
> +:- pred transform_state_vars(term, term, term, term, subs, varset, varset).
> +:- mode transform_state_vars(in, out, in, out, in, in, out) is det.
...
> + % Ensure that we transform functions so that the RHS
> + % of the `=' is considered as part of the body.
> + %
> + ( if
> +
> + Head1 = functor(atom("="), [LHS, RHS], C)
> +
> + then
> +
> + varset__new_var(VarSet0, X, VarSet1),
> + Head2 = functor(atom("="), [LHS, variable(X)], C),
> + Body2 = Body1 `conj` functor(atom("="), [variable(X), RHS], C)
> +
> + else
> +
> + VarSet1 = VarSet0,
> + Head2 = Head1,
> + Body2 = Body1
> + ),
Does this match the documentation above?
I would argue that the following should be equivalent:
p(!.A, !:A) :- !:A = !.A + 1.
f(!.A) = !:A :- !:A = !.A + 1.
In your implementation, I think they are transformed into:
p(A_0, A_1) :- A_1 = A_0 + 1.
f(A_0) = A_3 :- A_1 = A_0 + 1, A_3 = A_2.
You also don't have any test cases for functions using state variables.
Simon.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list