3 ms·
> Is it awful? The same happens in other languages like Python or C if I'm not mistaken. It annoys the shit out of me in python. I much prefer perl's for
by mst 5y ago
> Is it awful? The same happens in other languages like Python or C if I'm not mistaken.
It annoys the shit out of me in python. I much prefer perl's
for my $x (@array) { ... }
or ES6's
for (let x of array) { ... }
Note that given python and ruby only do function level scoping rather than block level, I can -understand- why they work the way they do even if it annoys me. R already has the necessary granular scoping to do the (IMNSHO) sensible thing so it seems like a pointless wart.
My -guess- would be that if it was intentional, it came about in R because for loops are rare enough that you want to know the last index more often than you don't because if you don't care about the index presumably you'd've written something else.
(also you could argue the ES6 version would be better written using 'const', but I've lisped sufficiently my fingers invariably generate 'let' when left to their own devices - caveat emptor)