Repository navigation
vcalc: allow declarations in conditionals and loops - #151
Conversation
…oping in scoping.rst
|
|
||
| #. | ||
|
|
||
| .. _clarify:no-decl-cond: |
There was a problem hiding this comment.
This clarification is completely legitimate. Why are you removing it?
There was a problem hiding this comment.
This clarification applies to scalc, which has only global scope. You copied it over verbatim when merging the scalc docs into bcalc to make it consistent, but vcalc has scoping rules that make this clarification false. See the example from 2020 in scoping.rst
There was a problem hiding this comment.
I copied it over because there's nothing wrong with it. The example is correct, in that the program is illegal as written. In SCalc it wasn't obviously illegal because of the global scoping. In VCalc it is still illegal because of the local scoping.
There was a problem hiding this comment.
Well sure, the example is illegal, but not because of the declaration. It is illegal because you are using a variable outside its scope. The declaration clarification is only useful for when you have global scope and this is not a problem.
|
|
||
| **no-decl-loop**: | ||
|
|
||
| Declarations in loops can lead to undefined or repeatedly defined |
There was a problem hiding this comment.
This is the same as the conditional declaration. The loop's scope ends at pool (and the if's scope ends at fi) so the uses in the examples are outside the scope and "obviously" illegal. Are the students confused because they don't understand why the clarification is needed?
There was a problem hiding this comment.
Note this says, “due to global scoping”, while vcalc has local scopes
There was a problem hiding this comment.
Exactly. You removed 20+ lines of semi-interesting clarification because the 4 words you highlighted are incorrect. Do you think the examples you removed are legal in vcalc?
There was a problem hiding this comment.
Neither of these clarifications are about using variables outside the scope. The examples happen to do that. The clarifications say you cannot perform variable declaration inside if statements or loops, which is not true. You’ve been able to do that for years (see the commit history). Both of these clarification only ever applied to scalc, they do not belong in a vcalc spec and they contradict the example in scoping.rst. The clarification is semi interesting but it is also just not true.
| it is possible to violate the property of variables stating that | ||
| :ref:`variables can only be defined once <variable-props>` by repeating | ||
| the declaration. For example, the following test would break this | ||
| property and is therefore invalid: |
There was a problem hiding this comment.
I admit I don't understand why this example is invalid.
The clarifications were from scalc and do not actually apply to vcalc, which has scoping.