Feedback and comments on ARM proposal - resend

Neal Gafter neal at
Thu Mar 19 12:17:33 PDT 2009

On Wed, Mar 18, 2009 at 5:18 PM, Howard Lovatt <howard.lovatt at> wrote:
> For example suppose as Neal has suggested
> that the foreach loop understood resources, it would be great to write
> something like:
>    for ( final String line : AutoResources.asLines( filename ) ) { ... }


I think you may have missed my point.  It isn't the Iterable that the
for-each loop needs to handle as a resource, because the programmer
can easily do that himself

try (final AutoResource linesInFile = AutoResources.asLines(filename)) {
  for ( String line : linesInFile ) {

Rather, I'm talking about the implicit Iterator variable that is
created by the expansion of the for-each loop.  Unlike Iterable,
Iterators are one-shot, so making one a resource is natural.  But,
with the current ARM proposal, there is no way to use the for-each
loop with an Iterable whose Iterator is an AutoResource.  Experience
with C#'s foreach loop and IDisposable/IEnumerable has shown the
combination to be very useful, as it avoids some very awkward
situations when both resources and loops are used together in a

These kinds of issues make me think that more actual experience with
the proposed construct will be required before we can have confidence
that it is "right".


More information about the coin-dev mailing list