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

Peter Driscoll peter_driscoll at bigpond.com
Wed Apr 3 09:52:19 AEST 2002


With stronger compiler support for list appending could we do without DCG?
Where we unify,
	InputList = FrontList ++ SomeOtherList
could (or is) the compiler smart enougth to realise that it needs to unify
FrontList with something, before trying to unify SomeOtherList.  In which
case the ordering achieved by DCG is implicitly given by the compiler
without the need for a special syntax.

It be nice to have greater freedom with modes for functions.
It would be nice to be able to use space as an operator,
	:- func list(T) list(T) = list(T).
	L1 L2 = list__append(L1, L2).

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

Regards

Peter Driscoll
----------------------------------------
Examples.

BNF
---
term ::= factor "*" term
term ::= factor "/" term
term ::= factor

Mercury using DCG.
------------------
:- pred term(list(char)::in, list(char)::out) is nondet.
term --> factor, ['*'], term.
term --> factor, ['/'], term.
term --> factor.

Mercury using concatenation
---------------------------
:- pred term(list(char)) is semidet.
term(Factor ++ ['*'] ++ Term) :-
	factor(Factor), term(Term).
term(Factor ++ ['/'] ++ Term) :-
	factor(Factor), term(Term).
term(Factor) :-
	factor(Factor).

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