[mercury-users] Suggested DCG extension

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Apr 1 18:41:21 AEST 2002

On 01-Apr-2002, Peter Driscoll <peter_driscoll at bigpond.com> wrote:
> It seems to me that the problem with DCG is that you only get one pair or
> in/out variables.

This is true.  This issue has been noted many times in the past.
Several different solutions have been proposed.
A couple of solutions ("EDCGs" and "state variables")
have even been implemented in the Mercury compiler.

As yet none of these solutions have achieved sufficient support
to be included in the main CVS distribution.  However, Ralph Becket's
"state variables" proposal has achieved concensus on in-principle support
for the design.  Ralph posted an implementation to the mercury-reviews
mailing list, but Simon Taylor noted a few serious problems with this
implementation.  Ralph continues to work on the implementation.
Hopefully it will be included in the next release of Mercury.

In the mean time, if you want to thread more than one variable,
you can use DCGS with a record type; there is special DCG syntax
for accessing record fields.  For example:
	:- type mystate ---> mystate(field1 :: type1, field2 ::type2).

	:- pred foo(mystate::in, mystate::out) is det.
	foo -->
		^field1 = X0, { bar(X0, X) }, ^field1 := X,
		^field2 = Y0, { baz(Y0, Y) }, ^field2 := Y.
	:- pred bar(type1::in, type1::out) is det.
	:- pred baz(type2::in, type2::out) is det.
	:- pred quux(mystate::in, mystate::out) is det.

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list