[PRL] disallowing shadowing

David Herman dherman at ccs.neu.edu
Sun May 29 17:25:18 EDT 2005


> Every fragment of my program is going to affect what changes I can  
> make to its outer context.  This means that every time I want to  
> introduce a new global name, rather than merely inspecting the  
> current list of global names, I'll have to inspect the entire  
> program text to ensure that there are no collisions.

Sure. That's not much different than the way I described it, although  
you have a point that it's more of a problem for adding things at the  
top than at the bottom. But if you subscribe to the idea of  
modularity, your program modules should never grow very big anyway,  
so scalability shouldn't be that problematic.

> Look, how about this way of looking at things: you know that  
> systems programming language, what's it called . . . C?  It has a  
> pretty restrictive set of rules for what you name procedures.  You  
> should try programming in that for a while and let us know how it  
> turns out.

Feeling snarky today, are we? I have written plenty of C programs,  
thank you very much.

As for the particular issue of C procedure names, if you mean that  
they all go in a global namespace, that's not quite the same thing.  
Mzscheme doesn't let you reuse top-level bindings, either, but the  
module system allows you to rename them or not to import them at all.  
That's different from shadowing. (I'm currently of the opinion that  
although you can *model* the binding semantics of module systems  
using just the lambda calculus, it's not the same thing as local  
binding, and the two should be conceptually distinguished.)

Java is closer to the semantics I was describing:

     ...
     int x = 1;
     {
         int x = 2;
         System.out.println(x);
     }

Test.java:5: x is already defined in main(java.lang.String[])
             int x = 2;
                 ^
1 error

Essentially the same program compiles and runs fine in C.

I'm especially interested in subtle ways this prohibition of local  
rebinding might interfere with other PL features, or if there are  
other deep reasons for the idea of shadowing.

Dave




More information about the PRL mailing list