News for hackers. Stuff that matters.
Re:Philosophy and "for" loops — more from Go and Rust by kibwen on Thursday July 11, 2013 @10:36AM (#6026252)
Ack, what bad timing. Rust is in the middle of switching its dominant iteration idiom from internal iterators to external iterators. See also:

https://github.com/mozilla/rust/wiki/Doc-detailed-release-no...

http://journal.stuffwithstuff.com/2013/01/13/iteration-insid...

The `for` construct will be changing in the 0.8 cycle to reflect this change. Currently it looks like:

  for [1,2,3].each |i| { /* a closure */ }
Where eventually it might look something like:

  for i in [1,2,3] { /* just a regular block */ }
I'm actually surprised that the author praises the "freedom and flexibility" of our old `for` loops... the reason for making this switch at all is because we found our old semantics to be neither sufficiently composable nor sufficiently flexible! :)

Hopefully the author will revisit this space once the new implementation is finalized, perhaps with a comparison to D this time.

TL;DR: Rust is switching idioms from Ruby-style iteration to C#-style iteration because (for our purposes) it's more performant, easier to optimize, more composable, and more flexible.

Re:Philosophy and "for" loops — more from Go and Rust by chrismorgan on Thursday July 11, 2013 @11:50AM (#6026806)
Well, in 0.7 the external iterator `each` pattern is mostly gone, leaving external iterators the standard style, but because the semantics of `for` haven't changed yet, there is an `advance` method provided for iterators, such that the code is actually at present thus:

    for [1, 2, 3].iter().advance |i| { /* a closure */ }
Re:Philosophy and "for" loops — more from Go and Rust by kibwen on Thursday July 11, 2013 @12:11PM (#6026958)
Right, I was hoping we could avoid mentioning this brief and ugly interlude in our evolution. :)
Re:Philosophy and "for" loops — more from Go and Rust by bjz_ on Thursday July 11, 2013 @05:53PM (#6029498)
It's been a courageous effort by strcat, pushing such ugliness on us over the 0.7 milestone, but it will certainly pay off into the future. I look forward to the new sugar!
Re:Philosophy and "for" loops — more from Go and Rust by anonymous on Thursday July 11, 2013 @01:11PM (#6027404)
That is basically a while loop without a "proper body", right? At each iteration advance is called with the closure as first argument and iteration continues until it returns false?
Re:Philosophy and "for" loops — more from Go and Rust by kibwen on Thursday July 11, 2013 @02:24PM (#6028038)
You're correct. You can see as much here in the implementation of `advance` (as you'd expect, it's very simple):

https://github.com/mozilla/rust/blob/master/src/libstd/itera...