First, this is rust, not scheme: http://doc.rust-lang.org/reference.html#statements-and-expressions. Regardless, the important part is not how many features the compiler supports, it’s how many features the user needs to learn. I’d argue that this proposal, from a learnability perspective, is a negative feature because it simply makes loops behave more like other expressions (if/match) and makes break statements behave more like return statements. While your closure example works, it’s much less readable (which, IMHO, is the most important feature in a language).
If you’re looking for a better example than the contrived find one, consider the following:
/// Without the feature
fn main() {
let maybe_name;
println!("Please enter your name or 'random' to be assigned a random name: ");
loop {
match get_input() {
Some("default") => {
maybe_name = None;
break;
},
Some(inp) => {
maybe_name = Some(inp);
break;
},
_ => println!("You didn't enter a name... Try again: ")
}
}
let name = match maybe_name {
Some(name_tmp) => name_tmp,
None => generate_name(),
};
println!("Hello {}", name);
}
/// With the feature
fn main() {
println!("Please enter your name or 'random' to be assigned a random name: ");
let name = loop {
match get_input() {
Some("default") => break generate_name(),
Some(input) => break input,
_ => println!("You didn't enter a name... Try again: ")
}
};
println!("Hello {}", name);
}
Yes, this could be done with a closure but then you need an extra closure.