[m-dev.] State variable syntax - last call for opinions

Peter Schachte schachte at cs.mu.OZ.AU
Fri Feb 1 00:07:48 AEDT 2002


On Thu, Jan 31, 2002 at 04:50:08PM +1100, Ralph Becket wrote:
> After more discussion here in the office, we've decided you're right:
> - it should be an error for either !.X or !:X to appear without the
>   other somewhere in the same clause;

That's not what I was advocating, and seems too strict and arbitrary.
I may have a number of predicates that thread around a variable X and
therefore want to use the !X notation throughout.  But for a predicate
that only produces or only consumes X, only one of !:X or !.X will
appear.  Eg, I see nothing wrong with this code:

	use_x(!.X) :-
		foo(!.X).

or this

	produce_x(!:X) :-
		!:X = 42.

Granted, you could write the same code without the !. and !:, but as I
said you may want to use them for consistency.

> - also it should be an error for !.X to appear before !:X except in the
>   head of the clause.

That's half of what I was suggesting.  The other half is to issue a
warning when the last !:X in a clause does not have a later !.X nor a
!:X (or !X) in the clause head.  The first half is akin in a
conventional language to an error for an unitialized variable, and the
second to a warning for a variable that is initialized but never used.

Eg,
	foo :-
		p(!.X).

should be an error and

	foo :-
		p(!:X).

should get a warning.

> > > > Is it an error to have multiple !:X in the same atom?  I think it
> > > > probably should be.  You could give it a sensible meaning, but I think
> > > > it would be too confusing to use.
> > > 
> > > I'd rather stick with a simple, general transformation and let the
> > > programmer learn to avoid baroque coding styles the hard way.

How cruel!  It would be far more helpful (and in keeping with the
spirit of Mercury IMHO) to warn programmers when they do something
that's almost certain to be an error, especially where confusing
constructs are concerned.  The rule "only one !:X (for each X) per
atom" is pretty simple.

-- 
Peter Schachte              The greatest dangers to liberty lurk in
schachte at cs.mu.OZ.AU        insidious encroachment by men of zeal,
www.cs.mu.oz.au/~schachte/  well-meaning but without understanding.
Phone: +61 3 8344 9166          -- Justice Louis D. Brandeis 
--------------------------------------------------------------------------
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