That form of iteration is common from Ruby, which is where I'm guessing
this interest is coming from? Ruby has the block/proc/lambda distinction
that makes the for loop and .each forms behaviorally similar, whereas in
Julia, there's just the one kind of anonymous function. As a result, if
this were made to work, enumerate(a) do i,x and for (i,x) in enumerate(a)
would not behave exactly the same – return in the former would exit the
current loop iteration whereas return in the latter exits the enclosing
function. I'm not sure it's a good idea to introduce too many different
ways to write this. If we were going to implement this, we wouldn't do it
by adding language features, but by adding methods to iterator-producing
functions like enumerate. In this case, you could do something like this:

function enumerate(f::Callable, x)
  for (i,x) in enumerate(x)
    f(i,x)
  end
end


That pattern could be emitted by a macro, of course.

Reply via email to