[mercury-users] Is DCG really appropriate, even for the things it does well?

Peter Driscoll peter_driscoll at bigpond.com
Thu Apr 4 13:24:39 AEST 2002

> The thing is that sometimes you really don't want to get bogged down
> writing pure Prolog-style code and syntactic support is necessary.

As an example of the the HLDSn veriables in the mercury_compile predicate
in mercury_compile.m look they could be DCG-ed, which would reduce some
ugliness.  As another example when translating an imperative language into
mercury.  Has anybody done any work on this?

On reflection I have no problem with you adding the state variables
functionality.  I suspect that everything done with state variables may be
done in other ways that preserve most of the structure of the code which
uses state variables, but maybe that doesn't matter.

I look forward to trying out state variables to see how they look.

> Sorry, I'm still unclear: are you including DCGs in "existing syntax"?

By existing syntax (I meant without DCG's). Apologies for the confusion.

Kind Regards

Peter Driscoll

One more way of doing DCG like things, using a database/timestamp approach.

	x_1(DCG_1, DCG2), x_2(DCG_2, DCG_3), x_3(DCG_3, DCG_4)

is equivalent to

	timestamps = xx_1(Database) + xx_2(Database) + xx_3(Database)

	:-	func xx_1(list(T)::in) = list(int)::in.
	xx_1(Database) = [TS] :- x_1(at(Database(TS)), at(Database(TS+1)).
	% same for xx_2 and xx_3.

	%	Define an infinite sequence of integers that represent points in time.
	:- func timestamps = list(int) is det.
	timestamps = timestamps2(1).

	:- func timestamps2(int) = list(int) is det.
	timestamps2(X) = [X | timestamps2(X+1)].

	%	This is just to allow me to treat a list as an array.
	%	Of course the database need not be stored as a list of values.
	%	We could store the database as a sequence of changes, or
	%	in a relational database.
	:- func at(list(T)::in, int::in, int::in) = T::out.
	at(X, N) = at(X, N, 1).

	:- func at2(list(T)::in, int::in, int::in) = T::out.
	at2([X | Y], N, M) =
		Result :-
			N = M
			Result = X
			Result = at(Y, N, M+1)

The point?  Just another way of doing DCG like things using lists.  Also
allows me
to manage the series of states.

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