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

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Apr 3 20:43:21 AEST 2002


On 03-Apr-2002, Peter Driscoll <peter_driscoll at bigpond.com> wrote:
> With stronger compiler support for list appending could we do without DCG?

Perhaps, but this would require significant extensions to determinism
analysis.

> Note: "Mercury using concatenation" below won't compile under mercury
> because
> 	mode list_append(in, in) = out.

Actually the list__append/3 predicate has several modes.
The function versions of list__append in the standard library don't --
I'm not sure why, exactly.  But you can easily write your own function
version which does, e.g. using "+" or "`app`":

	:- func list(T) + list(T) = list(T).
	:- mode in + in = out is det.
	:- mode out + out = in is multi.
	X + Y = Z :- list__append(X, Y, Z).

However, the problem that you run into for code like you suggest,

	term(Factor + ['*'] + Term) = times_term(factor(Factor), term(Term)).
	term(Factor + ['/'] + Term) = divide_term(factor(Factor), term(Term)).
	term(Factor) = simple_term(factor(Factor)).

is that the compiler's determinism analysis can't tell that there
won't be more than one result; the different clauses might not be
mutually exclusive, and the calls to the `out + out = in' mode of `+'
might succeed more than once.

In this case, the determinism analysis required would have to be
a non-local analysis, since whether or not this grammar is ambiguous
depends on the definition of `factor'.

Maybe the best solution for cases like this would be to have a simple
mechanism for telling the compiler to check the determinism at run-time
rather than at compile-time.

-- 
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