[Nickle] Multiple definitions of variable names in same scope
do not cause an error
David M Guy
guyd at cs.pdx.edu
Mon Nov 10 15:07:18 PST 2003
But the following is a more common usage(imho):
/* BEGIN CODE */
int i;
for (i = 0; i < 10; i++)
if (test(i))
break;
if (i < 10)
return i;
/* save 'i' in separate variable if necessary */
for (i = 0; i < 20; i++)
if (test(i))
break;
if (i < 20)
return i;
/* END CODE */
And certainly this code does not suffer either way:
/* BEGIN CODE */
for (int i = 0; i < 10; i++)
if (test(i))
break;
/* END CODE */
Perhaps you could make a pragma, so the programmer could ask the
interpreter to enforce unique names? This would be greatly appreciated.
Thanks.
- David Guy
On Mon, 10 Nov 2003, Bart Massey wrote:
> 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))
> break;
> 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
> definitively.
>
> Thanks much for the report!
>
> Bart
More information about the Nickle
mailing list