4 ms·
Interesting idea, but once you add scoping: do { let value = prepare(); } while (value.is_valid) { process(value); } Can the second block of
by do_not_redeem 2y ago
Interesting idea, but once you add scoping:
do {
let value = prepare();
} while (value.is_valid) {
process(value);
}
Can the second block of the do-while see `value` in its lexical scope? If yes, you have this weird double brace scope thing. And if no, most non-trivial uses will be forced to fall back to `if (...) break;` anyway, and that's already clear enough imo.
- PaulDavisThe1st 2y agoLet me FTFY: do { let value = prepare(); while (value.is_valid) { process(value); }
- coldtea 2y ago>Can the second block of the do-while see `value` in its lexical scope? If yes, you have this weird double brace scope thing As long as it's documented and expected, it's not weird. The scope then is the whole "do-while" statement, not the brace.
- TrianguloY 2y agoThe scope should be unique, yes. In your example value should be visible. Your are right about the word double braces, but I can't think of an alternate syntax other than just removing the braces around the while. But in that case it may seem odd to have a keyword that can only be used inside a specific block...wich is basically a macro for a if(.)break; Maybe I'm too used to the c/java syntax, maybe with a different way of defining blocks?
- deleted 2y ago[deleted]
- adamc 2y agoThat seems more like a programmer expectations issue than something fundamental. Essentially, you have "do (call some function that returns a chunk of state) while (predicate that evaluates the state) ..." Hard to express without primitives to indicate that, maybe.