Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions vcalc/impl/clarifications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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.


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

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.

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:

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.


::

int i = 0;
loop (i < 2)
int j = 0;
i = i + 1;
pool;

#.

.. _clarify:empty-vector:
Expand Down
2 changes: 2 additions & 0 deletions vcalc/spec/scoping.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _sec:scoping:

Scoping
-------

Expand Down
24 changes: 6 additions & 18 deletions vcalc/spec/statements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Variables have a few properties:

- cannot be declared without initialisation.

- cannot be declared more than once in a *VCalc* program.
- cannot be declared more than once in the same :ref:`scope <sec:scoping>`.

Examples of valid declarations are:

Expand Down Expand Up @@ -131,14 +131,8 @@ A conditional in *VCalc* has the following form:
are not a valid condition. Remember, however, that integers undergo an
:term:`implicit conversion` to booleans.

- ``statement-*`` is any type of statement *except* a declaration. This
means there can be assignments, nested loops, nested conditionals,
and prints. There does not have to be any statements in the
conditional.

**Clarification:** Declarations in conditionals can lead to undefined
values due to global scoping. (:ref:`no-decl-cond <clarify:no-decl-cond>`)

- ``statement-*`` is any type of statement. There does not have to be
any statements in the conditional.

Loops
~~~~~
Expand All @@ -163,15 +157,9 @@ A loop in *VCalc* has the following form:
valid condition. Remember, however, that integers undergo an
:term:`implicit conversion` to booleans.

- ``statement-*`` is any type of statement *except* a declaration. This
means there can be assignments, nested loops, nested conditionals,
and prints. There does not have to be any statements in the loop, but
without side effects a loop will be infinite (unless it is never
entered).

**Clarification:** Declarations in loops can lead to undefined or
repeatedly defined values due to global scoping.
(:ref:`no-decl-loop <clarify:no-decl-loop>`)
- ``statement-*`` is any type of statement. There does not have to be
any statements in the loop, but without side effects a loop will be
infinite (unless it is never entered).

Print
~~~~~
Expand Down
Loading