[m-dev.] Fw: Replacement syntax for DCGs

Ralph Becket rafe at cs.mu.OZ.AU
Mon Nov 26 15:22:41 AEDT 2001


Zoltan Somogyi, Monday, 26 November 2001:
> On 26-Nov-2001, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > 1. Any show stoppers in there?
> 
> I can see three problems right off.
> 
> First, the proposal does nothing about the common case that a value being
> threaded through is read-only inside some calls and read-write inside others.
> This could probably be fixed by using a second operator (maybe question mark)
> instead of exclamation mark.

This is a problem that already exists with DCGs and has the same
work-around (namely, `x ! =(X), foo(..., X)').  I don't have a problem
with introducing extra syntax to simplify the case.

> Second, it doesn't shorten calls, indeed, it makes lines containing calls
> that access threaded values even longer.

It does have the advantage that it makes the threading explicit and
costs no more than would be the case for an imperative language, for
example.

Personally, I'd prefer some explicit notation over hidden threading.

> Third, sometimes one does thread a value through most calls in the body of
> a predicate (the code generator has such examples). In that case, your
> notation would look horribly cluttered.

I disagree - a whole sequence of IO operations, for instance, would just
look like this:

io ! main :-
	io ! print("Hello, "),
	io ! print("world!"),
	io ! nl,
	...

That doesn't look cluttered to me, whereas

main -->
	{ ... },
	{ ... },
	{ ... },
	{ ... },
	read(...),
	{ ... },
	{ ... },
	print(...).

does.

> Has anyone tried to make a EDCG-like system by a mechanism such as
> transforming:
> 
> p(..., cur X, next X) :-
> 	p1(cur X),
> 	p2(cur X, next X),
> 	p3(cur X, next X).
> 
> into
> 
> p(..., X0, X2) :-
> 	p1(X0),
> 	p2(X0, X1),
> 	p3(X1, X2).
> 
> and
> 
> q(...) :-
> 	q1(define X),
> 	q2(cur X, next X),
> 	q3(cur X, next X).
> 
> into
> 
> q(...) :-
> 	q1(X0),
> 	q2(X0, X1),
> 	q3(X1, X2).
> 
> You'd have to put restrictions on atomic goals (number of occurrence of
> "cur X" or "define X" per goal <= 1, number of occurrence of "next X" per goal
> <= number of occurrence of "cur X" in that goal). And it would be tempting
> to try to apply "replacing equals with equals) to those occurrences of
> "cur X" above.
> 
> I am not proposing this system, just asking if anyone has done it.

I proposed exactly this idea several years ago, using just "X" rather
than "cur X" and "X`" rather than "next X" - this was before back-quote
was taken for infix notation.

That proposal could be revived.

- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list