[m-dev.] Adding Loops to Mercury

Paul Bone paul at bone.id.au
Thu Jan 2 19:26:39 AEDT 2014


On Thu, Jan 02, 2014 at 06:20:27PM +1100, Julien Fischer wrote:
> On Thu, Jan 2, 2014 at 5:50 PM, Michael Day <mikeday at yeslogic.com> wrote:
> 
> > Hi Paul,
> >
> >
> >  foreach I=std::fromTo(1,1000) do
> >>>     %...whatever
> >>> end foreach.
> >>>
> >>
> >> I think that such a feature would be considered "not in the spirit of
> >> Mercury" by most developers.
> >>
> >
> > Light syntax and efficient compilation for lambdas is enough:
> >
> >     foreach(1 `..` 100, func(X) = blah)
> 
> 
> Which is pretty much already supported, e.g.
> 
>       map(func(X) = X * 2, 1 `..` 100)
> 
> (Use a quantifier like foreach seems like the wrong name to use
> for some that is transform the list of integers using a function.)

foreach would be a predicate that is very similar to list.foldl.

There's no need to introduce a language feature when you can write the
relevant abstraction directly.


-- 
Paul Bone
http://www.bone.id.au



More information about the developers mailing list