Repository navigation
vcalc: allow declarations in conditionals and loops #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,67 +20,6 @@ specification without cluttering it. | |
| you are left with is a single empty line, which matches "*should* be | ||
| an empty line at the end of your output". | ||
|
|
||
| #. | ||
|
|
||
| .. _clarify:no-decl-cond: | ||
|
|
||
| .. container:: | ||
| :name: no-decl-cond | ||
|
|
||
| **no-decl-cond**: | ||
|
|
||
| Declarations in conditionals can lead to undefined values due to | ||
| global scoping. Because of the potentially conditional nature of the | ||
| execution, it is possible to violate the property of variables | ||
| stating that :ref:`variables must be defined before being used <variable-props>` | ||
| (not just declared) by never executing the | ||
| definition. For example, the following test would break this property | ||
| and is therefore invalid: | ||
|
|
||
| :: | ||
|
|
||
| if (1 < 0) | ||
| int i = 0; | ||
| fi | ||
| int j = i; | ||
|
|
||
| #. | ||
|
|
||
| .. _clarify:no-decl-loop: | ||
|
|
||
| .. container:: | ||
| :name: no-decl-loop | ||
|
|
||
| **no-decl-loop**: | ||
|
|
||
| Declarations in loops can lead to undefined or repeatedly defined | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same as the conditional declaration. The loop's scope ends at
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this says, “due to global scoping”, while vcalc has local scopes
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| values due to global scoping. Because of the potentially conditional | ||
| nature of the execution, it is possible to violate the property of | ||
| variables stating that :ref:`variables must be defined before being used <variable-props>` (not just declared) by never executing the | ||
| definition. For example, the following test would break this property | ||
| and is therefore invalid: | ||
|
|
||
| :: | ||
|
|
||
| loop (1 < 0) | ||
| int i = 0; | ||
| pool | ||
| int j = i; | ||
|
|
||
| As well, because of the potentially repeated nature of the execution, | ||
| 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: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I admit I don't understand why this example is invalid. |
||
|
|
||
| :: | ||
|
|
||
| int i = 0; | ||
| loop (i < 2) | ||
| int j = 0; | ||
| i = i + 1; | ||
| pool; | ||
|
|
||
| #. | ||
|
|
||
| .. _clarify:empty-vector: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .. _sec:scoping: | ||
|
|
||
| Scoping | ||
| ------- | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clarification is completely legitimate. Why are you removing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.