Does anyone use 'with' statement?

Bill Baxter dnewsgroup at billbaxter.com
Sun Dec 9 01:53:28 PST 2007


Xinok wrote:
> I can see where with statements can make code harder to read. I think 
> it's important to make it more explicit, so others reading your code 
> don't have to guess where a symbol is coming from.
> 
> We could overload the global operator to do just that. It's purpose 
> changes when it's used in the with statement.
> 
> class N{
>     int a, b, c;
> }
> 
> void main(){
>     int a, b, c;
>     N obj = new n;
>     with(obj){
>         a = 35; // main.a
>         .a = 60; // obj.a
>     }
> }

I'd like to see it be a shadowing error if you try to use 'a' inside 
with(obj) when 'a' is both a member of obj and the enclosing scope, as 
above.

And I think '.a' is already used elsewhere to mean the 'a' from the 
_outer_ scope.  Maybe I'm imagining that though... I've never actually 
used it, but I was thinking I read that was D's version of ::a from c++.

Note that if you need to differentiate you can also still refer 
explicitly to "obj.a" inside the with(obj) block.  "obj" doesn't cease 
to exist as a symbol.

--bb



More information about the Digitalmars-d mailing list