首页

New for loops in Rust

41 点作者 nikomatsakis大约 13 年前

6 条评论

chubot大约 13 年前
I'm going to make a superficial comment and say that "cont" and "ret" are annoying and gratuitous differences. C/C++, Java, Python, JavaScript, and I think Perl/Ruby/Go all use "continue" and "break". It's just pointless to be different in this respect.<p>A different concept should use different syntax -- and it looks like Rust has several new concepts where they can invent whatever syntax they want. But the same concept should use the same syntax.
评论 #3806555 未加载
评论 #3807220 未加载
评论 #3808906 未加载
评论 #3806477 未加载
vilya大约 13 年前
This looks like a bad design. It means either (a) the semantics of 'ret' inside a lambda function can change depending on the call site (whether it's used inside a for loop or not); (b) that a lambda function passed in from elsewhere can cause your function to return early; or (c) that lambda functions have different syntax rules depending on where they're being defined. All of which seem equally bad!<p>I hope there's something I've missed. I've been quite impressed by the rest of the language so far &#38; it would be a shame if they got this wrong.
评论 #3807892 未加载
评论 #3807474 未加载
评论 #3807971 未加载
kibwen大约 13 年前
For anyone who's wondering what the point of all this is, here are the discussions that help to explain the impetus for this change:<p><a href="https://mail.mozilla.org/pipermail/rust-dev/2012-February/001432.html" rel="nofollow">https://mail.mozilla.org/pipermail/rust-dev/2012-February/00...</a><p><a href="https://mail.mozilla.org/pipermail/rust-dev/2012-March/001490.html" rel="nofollow">https://mail.mozilla.org/pipermail/rust-dev/2012-March/00149...</a><p><a href="https://github.com/mozilla/rust/issues/1619" rel="nofollow">https://github.com/mozilla/rust/issues/1619</a><p>As far as I remember it has to do with the prior inability to handle non-local returns and the desire to honor Tennent's Correspondence Principle.
frewsxcv大约 13 年前
Seems a bit...overly complex.<p>Also, what is the appeal to '::' instead of just '.'<p>Kill the semicolons with fire
评论 #3806535 未加载
p4lindromica大约 13 年前
Why is there so much sugar?! Can't a keyword just be a keyword?
评论 #3806393 未加载
评论 #3806356 未加载
gioele大约 13 年前
&#62; the new for will work on any higher-order function with the appropriate signature<p>In the end this makes Rust loops look like Ruby loops. May I restate that «widely used programming languages are modified until they resemble Ruby» (<a href="https://news.ycombinator.com/item?id=3448277" rel="nofollow">https://news.ycombinator.com/item?id=3448277</a>) or CLispScript (<a href="https://news.ycombinator.com/item?id=3448826" rel="nofollow">https://news.ycombinator.com/item?id=3448826</a>).<p>What I do not understand of the late "scripting" languages (Dart, Rust) is why they don't just modify Ruby to have a stricter type system and call it done? That or just abandon the scripting mindset and go for more purely functional languages with non-C-like syntaxes like Haskell or OCaml.
评论 #3806553 未加载
评论 #3806828 未加载