[Nickle] Multiple definitions of variable names in same scope do not cause an error

Bart Massey bart at cs.pdx.edu
Mon Nov 10 14:44:26 PST 2003

In message <Pine.GSO.4.58.0311101318390.28639 at sirius.cs.pdx.edu> you wrote:
> I wrote some nickle test code in which I made a copy/paste error,
> accidentally declaring a variable name twice, but the interpreter did not
> raise an error.
> Question: Is this a bug or by design?

By design. Each new definition of a name creates a new
variable, and they are all scoped properly.  So it is
normally harmless.

OTOH, it's a bug that the manual doesn't make this clear.

> Personally, I would prefer if the interpreter considered
> this an error.

Or perhaps a warning.  But keep in mind that there are some
useful idioms that would be borken if we did this, e.g.

	int i;
	for (i = 0; i < 10; i++)
	    if (test(i))
	if (i < 10)
	    return i;

could not be repeated in a scope.

It's a tough design call, and one on which we've waffled in
the past.  We expect that most redefinitions are not errors,
but it would take an empirical study to figure it out

Thanks much for the report!


More information about the Nickle mailing list