We do not have a tutorial document yet, so misunderstandings are inevitable.
> I was surprised anyway. Eiffel always prided itself for having only one
> good way of doing things - now we are getting a second loop construct.
> What's next?
There is no new construct, only a small extension of the existing loop construct, which remains the only loop mechanism in Eiffel. The extension follows the long-standing Eiffel tradition of providing shortcuts for common cases, with the new variants defined in terms of the basic ones. The basic idea is simple: you may abbreviate the common pattern
[1] from
l.start
until
l.after
loop
some_action (l.item)
l.forth
end
as
[2] across l as ll do some_action (ll.item) end
The mechanism also offers `some' and `all' forms, useful in particular for contracts, as in
[3] across l as ll all ll.item > 0 end
The language definition introduces [2] explicitly as an abbreviation for [1], and similarly for [3], so there is nothing really new. The invariant clause can and should still be there. The variant can also be included, as well as the `until' clause if the iteration must stop before the end of the structure. The `from' clause too can appear, if an explicit initialization is required. So it's the good old Eiffel loop construct as we have always had it, with a simplified form covering the common case of iterating on a linearizable data structure (the type of `l', e.g. a list type, must be based on a descendant of the library class ITERABLE).
There will remain "one good way" to do loops. For standard cases of data structure iteration, [2] and [3] are more concise and avoid the risk of forgetting the call to `forth'. [1] will remain useful for sophisticated cases in which the programmer needs finer control, for non-data-structure-related loops, and possibly to teach beginners what [2] means. In addition, the new versions carry, in the current implementation, a performance penalty, causing some programmers to retain the original form in time-critical loops for the time being.
To avoid perpetuating the misunderstandings, I have made available temporarily at
http://se.ethz.ch/~meyer/down/temp-loop/iterloop.htmla copy of the ECMA TC49-TG4 committee's working document. Caveats:
- This is not a tutorial but a technical specification in
the style that we are using for language evolution proposals
within the committee. It is not designed to be easy to
understand by newcomers; you need to know the existing
standard well, and probably to read the new document
twice anyway. Still, reading sections 1 and 2 will give
you a good idea of what this is about.
- The mechanism is in EiffelStudio 6.5 but experimentally,
and you will not be able to use it effectively until
EiffelBase has been adapted (to make iterable classes
such as LIST and HASH_TABLE inherit from the new
library class ITERABLE, making examples such as the
above and those in section 2 of the document valid).
The updated, experimental EiffelBase will be released
in a few weeks.
A tutorial will be provided.
The mechanism is an incremental extension to an existing construct; my expectation, if the experiment succeeds, is that in a few months Eiffel programmers will be using it extensively.
-- BM
> -----Original Message-----
> From:
[hidden email]
> [mailto:
[hidden email]] On Behalf Of Jann Röder
> Sent: 15 November, 2009 12:39
> To:
[hidden email]
> Subject: Re: [eiffel_software] Re: New loop construct
>
>
>
> Sure it is more powerful, but this whole thing being a shortcut, I
> would
> assume its main purpose is to be short for probably 95% of its uses.
>
> I was surprised anyway. Eiffel always prided itself for having only one
> good way of doing things - now we are getting a second loop construct.
> What's next?
>
> Since the decision has already been made it is pointless to start a
> discussion, I'm just a bit confused.
>
> Jann
>
> Am 14.11.09 00:26, schrieb Emmanuel Stapf [ES]:
> >> In across container as c loop ... end,
> >> why do you always have to use c.item instead of just c? Is there
> >> anything else you can do on c except calling .item on it ?
> >
> > One thing you can do is query the `index' in the current iteration.
> It was debated over and we felt that providing the cursor rather than
> the item was much more powerful with little loss in the simplicity.
> >
> > Regards,
> > Manu
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
>
>
>