I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Talk:Variable declaration reset

From Rosetta Code

i>1[edit]

(minor point) I think I may have sold you all a bit of a dummy with Phix's i>1, which is correct because of it's 1-based indexes, and the JavaScript typo of i>1 which should have been/is now i>0, but luckily it should make no difference. I also wonder if algol68 should be i>LWB s ?? --Pete Lomax (talk) 02:07, 16 April 2022 (UTC)

God point, Pete - I've adjusted the code and added a bit more explanation. --Tigerofdarkness (talk) 13:15, 16 April 2022 (UTC)
Maybe a bit late now but you could make it lower-bound independent if it was curr>1 instead of i>1 - the effect would be the same. --Tigerofdarkness (talk) 11:13, 17 April 2022 (UTC)
Yeah, that would be(/have been) fine too. I also realised far too late that I should have asked for the values instead of the indexes, so we'd get consistent results across 0-based and 1-based indexes... Nevermind. --Pete Lomax (talk) 13:27, 17 April 2022 (UTC)

Meaning of purpose[edit]

I am having trouble understanding the meaning of the purpose of the task:

The purpose is to determine whether variable declaration (in block scope) resets the contents on every iteration.

Is there a language where a variable declaration inside the body of a loop does *not* reset the contents on every iteration? What would the alternative be like? --Spoon! (talk) 07:17, 21 June 2022 (UTC)

Is there a language where a variable declaration inside the body of a loop does *not* reset the contents on every iteration?
Yes?
What would the alternative be like?
The possible alternatives might be:
  • 1) It does reset every time.
  • 2) It doesn't reset every time.
or possibly...
  • 3) It does or doesn't reset depending on other factors. (see the Raku entry, for example)
--Thundergnat (talk) 10:40, 21 June 2022 (UTC)
The task arose because apparently identical (transpiled) code worked quite differently in different languages, specifically Phix (does not) and JavaScript (does for let, does not for var). The task, and the whole purpose of this site, is to highlight (subtle) differences between languages. It has certainly taught me (the author of the task) quite a few and sometimes rather surprising things. What the actual task itself does is deliberately trivial and pointless. So far I've got (cmiiw):
Does reset: Algol, C++, F#, Factor, Go, Java, Julia, Python[moreso than not], Vlang, Wren.
Does not: AWK, C (C99), FreeBasic, Phix, PL/M, Red, VisualBasic.NET.
Both: JavaScript, Raku. --Pete Lomax (talk) 12:49, 21 June 2022 (UTC)