Neat trick - 'with' and unnamed objects + 'with' proposals

Max Samukha samukha at voliacable.com
Tue Apr 24 10:18:24 PDT 2007


On Wed, 25 Apr 2007 01:53:56 +0900, Bill Baxter
<dnewsgroup at billbaxter.com> wrote:

>BCS wrote:
>> Bill Baxter wrote:
>>> BCS wrote:
>>>
>>>> Bill Baxter wrote:
>>>
>>>
>>>> how about take a trick from "if"
>>>>
>>>> with(auto name = new someGUIWidget(myParent))
>>>> {
>>>>    shown = true;
>>>>    focusable = false;
>>>>    some_global_function(name);
>>>> }
>>>
>>>
>>> Yeh, I was actually just thinking that myself, and was disappointed to 
>>> find out it doesn't work.  :-(
>>>
>>> Looking at the spec it seems that's special to 'if'.   It could be 
>>> useful for switch(), with() and synchronized(), but it seems it hasn't 
>>> been added.
>>>
>>> --bb
>> 
>> Ohhh. That would be nice in switch ... and while...
>
>I was thinking 'while' would have issues, because the condition is 
>evaluated multiple times.  So I left it off the list.  Maybe it's not a 
>problem though.  Just make it equiv to
>{
>    typeof(condition()) x;
>    while(x = condition()) {
>        // do stuff
>    }
>}
>
>--bb

This would be inconsistent with if(), which declares the variable to
be local to if's scope. BTW, it'd be nice to have the variable
declared outside the if block as you proposed for 'with'. I remember a
case or two when I wanted that.


   



More information about the Digitalmars-d mailing list