Skip to content

vcalc: allow declarations in conditionals and loops - #151

Merged
novo52 merged 1 commit into
masterfrom
vcalc-block-scoped-decls
Sep 30, 2026
Merged

novo52 merged 1 commit into
masterfrom
vcalc-block-scoped-decls

Conversation

@novo52

@novo52 novo52 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

The clarifications were from scalc and do not actually apply to vcalc, which has scoping.

@novo52
novo52 merged commit 1ad228d into master Sep 30, 2026
1 check failed
@novo52
novo52 requested a review from rcunrau September 30, 2026 22:31

#.

.. _clarify:no-decl-cond:

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

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.


**no-decl-loop**:

Declarations in loops can lead to undefined or repeatedly defined

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this says, “due to global scoping”, while vcalc has local scopes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit I don't understand why this example is invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants