[m-dev.] Feature proposal: generic inline iterations

Peter Stuckey pjs at cs.mu.OZ.AU
Thu Dec 22 15:36:27 AEDT 2005


On 22/12/2005, at 3:03 PM, Mark Brown wrote:

> Hi Sebastian,
>
> Thanks for writing down the details of this proposal; I'm fairly happy
> with this kind of language feature being added.  A couple of 
> preliminary
> remarks, though:
>
> On 22-Dec-2005, Sebastian Brand <sbrand at csse.unimelb.edu.au> wrote:
>> (1) At the core is a predicate do/2 whose first argument consists of
>> a sequence of
>>
>> 	fromto(First, In, Out, Last)
>>
>> expressions, describing the iteration control.  The second argument
>> is the iteration body, a sequence of regular Mercury statements.
>> Using infix notation, we have statements
>>
>> 	...
>> 	(
>> 	fromto(First1, In1, Out1, Last1),
>> 	fromto(First2, In2, Out2, Last2),
>> 	...
>> 	fromto(FirstN, InN, OutN, LastN)
>> 	do
>> 		%  the iteration body is any Mercury code, here
>> 		%  exemplified by a single predicate body/2N
>> 		%
>> 		body(In1, ..., InN, Out1, ..., OutN)
>> 	),
>> 	...
>

> Note that in order to parse the way we expect it to, do/2 will need to
> have a priority greater than 1000 (which is the priority of ','/2).
> I have no objection to adding such an operator.
>
> It would be nice if the new feature worked well with state variable 
> syntax.
> For example, using the above form, it could be possible to write
>
> 	fromto(First1, !Local1, Last1)
>
> but there would be no corresponding way to use a state variable for the
> non-local variables.  You would be forced to write
>
> 	fromto(!.Nonlocal1, !Local1, !:Nonlocal1)
>
> instead.  Perhaps the argument ordering could be changed to better 
> support
> state variable syntax (at the risk of confusing Eclipse users)?
>

Cant it simply be a higher order predicate


	do([ fromto(First1, In1, Out1, Last1),
	        fromto(First2, In2, Out2, Last2),
	        ...
	        fromto(FirstN, InN, OutN, LastN),
	        body
	)

then we dont need parsing changes.  Or is the existential type required 
not going to work?

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