[Python-ideas] Special keyword denoting an infinite loop
Devin Jeanpierre
jeanpierreda at gmail.com
Sat Jun 28 14:53:08 CEST 2014
On Sat, Jun 28, 2014 at 2:11 AM, Steven D'Aprano <steve at 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.
In Python, there is no special case at all, so there is no extra
keyword. As it should be.
Rust has some ideas Python could borrow, but this ain't one of them. -1.
-- Devin
More information about the Python-ideas
mailing list