[chuck-users] Scope bug?

Tom Lieber tom at alltom.com
Sun Aug 10 22:27:00 EDT 2014


Being able to redefine a variable in a tighter scope is a handy feature. It
lets you think locally about your program, which is easier than thinking
globally.

Imagine bar() was written first. Then adding foo to A would be an error—and
not because there’s anything wrong with A, but because someone somewhere
subclassed A and already used that variable in one of its functions. That’s
weird.


On Sun, Aug 10, 2014 at 7:42 AM, Casper Schipper <casper.schipper at gmail.com>
wrote:

> Should it not be simply forbidden to redefine a variable like that in a
> sub-class ?
> When you assign instead of declare, the problem disappears.
> So perhaps, instead of 'fixing' the bug, we should forbid this kind of use
> of scope (chuck should throw an error if you try) ?
>
> Casper
>
> class A
> {
>     10000 => int foo;
> }
>
> class B extends A
> {
>     fun void bar()
>     {
>         // 0 => int foo;
>         0 => foo;
>
>
>         <<< "a", foo >>>;
>         {
>             <<< "b", foo >>>;
>         }
>         <<< "c", foo >>>;
>     }
> }
>
> B b;
> b.bar();
>
>  Casper Schipper
> casper.schipper at gmail.com
> www.casperschipper.nl
> +316 52322590
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>


-- 
Tom Lieber
http://AllTom.com/
http://infinite-sketchpad.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20140810/a0bb2c5f/attachment.html>


More information about the chuck-users mailing list