[m-dev.] Adding Loops to Mercury
Peter Schachte
pschachte at gmail.com
Fri Jan 3 10:49:24 AEDT 2014
On 02/01/14 16:13, Michael Richter wrote:
> On 2 January 2014 10:41, John Adams <jpadams78 at gmail.com
> <mailto:jpadams78 at gmail.com>> wrote:
>
> Is there or plan (maybe already done) to add loops to Mercury
> Language?
>
> Visual Prolog has loops of the form:
>
> foreach I=std::fromTo(1,1000) do
> %...whatever
> end foreach.
>
>
> God I hope not!
I'm not sure why everyone takes such a dim view of looping. As long as
it's given a proper declarative semantics, I see nothing inconsistent
about loops in Mercury, and they could save us all from the huge number
of library predicates and functions that map over some (possibly
filtered lists) while folding over some other lists. The sheer number
of these suggests that there's some missing modularity, which a looping
construct could provide. The trouble with the fold/filter/map
predicates/functions is that they conflate the construction of the
result with the generation of the input and the control of the loop.
When they capture what you want, they're great, but when they don't,
they lead you to ask for yet another map2fold3filter1 predicate.
As for the semantics, a generalisation of Mercury's 'all' construct that
can generate output would fit well with Mercury. Here's a paper I wrote
a decade ago doing this for Prolog. At the time, Fergus Henderson told
me there was some shortcoming in Mercury's type or mode system that
would make this difficult to do for Mercury, but I don't remember the
specifics.
--
Peter Schachte Politics, n. A strife of interests
University of Melbourne masquerading as a contest of principles.
schachte at unimelb.edu.au The conduct of public affairs for private
www.cs.mu.oz.au/~schachte/ advantage. -- Ambrose Bierce, 1906 (The
Phone: +61 3 8344 1338 Devil's Dictionary)
I support the NTEU's campaign for a fair enterprise agreement.
Find out more: nteu.org.au/melb | facebook.com/nteu.unimelb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/developers/attachments/20140103/a4fea5ab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seq-quant.pdf
Type: application/pdf
Size: 258554 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20140103/a4fea5ab/attachment.pdf>
More information about the developers
mailing list