
On 28 June 2014 22:53, Devin Jeanpierre <jeanpierreda@gmail.com> wrote:
On Sat, Jun 28, 2014 at 2:11 AM, Steven D'Aprano <steve@pearwood.info> wrote:
On Sat, Jun 28, 2014 at 01:04:24AM -0700, Thomas Allen wrote:
Rust language defines a special way to make an infinite loop ( http://doc.rust-lang.org/tutorial.html#loops).
Do they give an explanation for why they use a keyword for such a redundant purpose?
Sure. "while true {...}" would require magic by the compiler to make it optimized and to make things like the following pass compile-time checks: "let a; while true { a = 1; break;}; return a". With a while loop, Rust can't really know that the loop executes even once without special-casing the argument, so it emits a compile-time error because the variable a might be uninitialized. If Rust magically knew about while true, then it becomes confusing if replacing "true" with something the compiler doesn't directly understand causes the compiler to get confused.
Special cases aren't special enough to break the rules, so Rust decides that the special case here deserves its own keyword.
Ah, that makes a lot of sense - I forgot that it wouldn't be just an optimisation for Rust, but a control flow validity checking change as well. Thanks for the explanation. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia