[m-dev.] Adding Loops to Mercury
Julien Fischer
jfischer at opturion.com
Thu Jan 2 19:30:18 AEDT 2014
On Thu, Jan 2, 2014 at 7:26 PM, Paul Bone <paul at bone.id.au> wrote:
> 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.
>
It wouldn't, you would need to provide the initial value of the accumulator
somewhere. In any case, my point was that foreach is not a good name
for such a thing.
Cheers,
Julien.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/developers/attachments/20140102/a8f6d442/attachment.html>
More information about the developers
mailing list