On 29/11/20 4:14 am, Paul Sokolovsky wrote:
On Fri, 27 Nov 2020 13:06:56 +1300 Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: There was no mix-up on my side, and neither seems there was on yours. Block-level scoping and const'ness are orthogonal, well composable features.
Someone (maybe not you) suggested "for const i = ..." as a way to address the problem of variable capture in for loops. The logic behind this seems to be: * If i is const, rebinding it each time round the loop is obviously impossible, therefore the loop body must be a new scope in which there is a different i for each iteration. * Since i is const, we don't need to capture it as a variable, so as an optimisation we can just capture its value. But this makes constness and new scopes non-orthogonal, because there's no way to have a new scope for a variable without making it const, and no way to make a variable const without creating a new scope for it. I also think that "const" is not an *obvious* solution to someone faced with the for-loop problem. They're not trying to reassign the variable anywhere, so there's no reason for constness to come to mind.
"for const" on its own doesn't make much sense (and neither "for new", i.e. adhoc workaround for the "for" case).
It's not so ad-hoc if "new" can be applied to any assignment. Also, if you think "for new" doesn't make sense, you're probably reading it incorrectly. The mental bracketing isn't "(for new) i", it's "for (new i)". This works with "new" and "const", because they're adjectives. But "let" isn't an adjective, so "for let i" doesn't make sense however you parse it. -- Greg _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RX6NTBY435I5YCO37NMZVDNNX4YMBQXY/ Code of Conduct: http://python.org/psf/codeofconduct/