[m-dev.] Reopened: state vars syntax sugar

Ondrej Bojar obo at cuni.cz
Mon Jan 29 12:13:41 AEDT 2007


Hi.

A slight problem is that ::! is a single token so:
:- pred p1(!foo::!ground) is det.

renders a syntax error and extra parentheses have to be used:
:- pred p1(!foo::(!ground)) is det.

or we need to tweak library/lexer.m
or library/ops.m to add "::!" as a new operator.
(Which is the preferred choice?)

To the other issue: There are two ways to avoid (syntax) wars: a) 
creeping featurisis, b) dictatorship. In this particular case, I would 
vote for a) and support both:

:- pred p(!type::!(in, out)) is det.
:- pred p(!type::!ground) is det.

The arity of ! makes a clear distinction between the inst/modes way of 
specification. For new users, modes are easier to comprehend, and state 
variables (popular for their conciseness beauty) could actually serve as 
a nice link for delving into instantiations.

But in case there is an approved dictator for syntax issues, I'm willing 
to obey.

Cheers, Ondrej.

P.S.: If there is no dictator, how do you arrive at final conclusions? 
(Two approvals for a diff justify a commit? That does not sound like a 
stable procedure if the environment ceased to be cooperative. ;-)

Peter Schachte wrote:
> Ralph Becket wrote:
> 
> 
>>What about running DCGs "backwards"?  We might want to do the same with
>>state variables.
> 
> 
> Touché!  And for the X>>dead mode, doesn't X have to be unique?
> And there is also an implied mode, and the mostly unique versions.
> 
> But they're still pretty orthogonal:
> 
> Forward	modes: 	       X>>Final, Initial>>X
> Backward modes:        Initial>>X, X>>Final
> 
> For normal versions:   Initial=free
> For implied versions:  Initial=X
> 
> Normal:                Final=X,
> Destructive:           Final=dead and X must be unique
> Unique:                Final=unique and X must be unique
> Mostly destructive:    Final=mostly_unique and X must be mostly_unique
> Mostly unique:         Final=mostly_dead and X must be mostly_unique
> 
> If that covers all useful cases, how about this for a syntax:
> 
>   !(X)                 means X>>X, free>>X
>   !destructive         means unique>>dead, free>>unique
>   !mostly_destructive  means mostly_unique>>mostly_dead, free>>mostly_unique
>   !input(X)            means X>>X, X>>X
>   !backward(X)         means B, A if !(X) means A, B
> 
> So most of the time, the mode for a state var would just be !ground, or
> occasionally !destructive, which look pretty good to me.  Also note that if
> Mercury ever supports ui modes, then !unique means (ui, uo).
> 

-- 
Ondrej Bojar (mailto:obo at cuni.cz)
http://www.cuni.cz/~obo


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list