|
|
Log in / Subscribe / Register

Rust's for-loop construct probably changed

Rust's for-loop construct probably changed

Posted Jul 3, 2013 19:39 UTC (Wed) by djc (subscriber, #56880)
Parent article: Philosophy and "for" loops — more from Go and Rust

Rust's for-loop semantics have been changed recently; I'm not sure if this has been reflected in the article yet? I'm guessing not, but I'm not familiar enough with the language semantics to say for sure.

http://thread.gmane.org/gmane.comp.lang.rust.devel/4528
http://static.rust-lang.org/doc/tutorial-container.html


to post comments

Rust's for-loop construct probably changed

Posted Jul 4, 2013 7:46 UTC (Thu) by renox (guest, #23785) [Link] (2 responses)

Yes, Rust "pulled a Linus" and changed the semantic of their "for" loops just at the same time that the LWN article was up.
A very interesting comparison of internal(callback) vs external(cursor) iterators:
http://journal.stuffwithstuff.com/2013/01/13/iteration-in...

It's also discussed here http://www.reddit.com/r/programming/comments/1hl2qr/rust_...

Also I think that in the context of iterators D ranges should have been part of the LWN article..

Rust's for-loop construct probably changed

Posted Jul 11, 2013 4:58 UTC (Thu) by eternaleye (guest, #67051) [Link] (1 responses)

Having read that article (and the sequel), there's one thing that bugs me a little about the tack Rust took. Rust *already* uses message-passing concurrency, and that allows a simple transformation from internal to external iterators by creating a stream, passing the chan into a task that runs the internal iterator (whose block closes over the chan), and then return or wrap an iterator for the port. So it startles me a bit that there isn't an Iterator implementation that does the transformation, yielding the best of both worlds.

Rust's for-loop construct probably changed

Posted Jul 11, 2013 23:35 UTC (Thu) by thestinger (guest, #91827) [Link]

You can currently use tasks to make an `Iterator` implementation, but context-switching for each iteration is too much overhead to be the iteration building block. C# has the ability to compile a generator to a state machine, and it's something Rust can implement in the future.

Rust's for-loop construct probably changed

Posted Jul 4, 2013 10:54 UTC (Thu) by cmrx64 (guest, #89304) [Link]

The `for` semantics have *not* been changed yet. 0.7 marks the introduction of robust external iterators (which are a much different style than the internal iterators discussed here, and much more easier to use). The `for` semantics will change, but they have not.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds