You might do this more with for, but the effect is the same, and it seems to me that any “fix” would at best not be worth the headaches and at worst would actually make the language syntax more complex while producing no significant benefits.

I think it’s in most cases it’s a bad idea to immediately reuse the yielded value. Name every intermediate result! Multi-line code without local definitions is a code smell. I see too much Scala code that ignores this principle, at the price of legibility.

However it would be interesting if we change the paradigm, and instead look at for comprehensions more like a de-nested flatMap chain, plus interleaved code which currently only can be assignments. In that perspective, other statements could potentially be allowed, including var and reassignment, and using the val keyword would make more sense. In other words think about allowing arbitrary code between generators.

I think it’s in most cases it’s a bad idea to immediately reuse the yielded value. Name every intermediate result! Multi-line code without local definitions is a code smell. I see too much Scala code that ignores this principle, at the price of legibility.

In most cases, yes. But I still occasionally run into the case of wanting to stick a (collections.breakout) at the end of a comprehension so that the types get massaged into the correct shape.

Some combination of SIP-12 (as in dotty), changing the parse rules to use those of better-monadic-for (is this in dotty yet?), and the 2.13 collections rewrite should make this problem go away