March 28, 2002 Re: Suggestion: way to get switch() value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Krehbiel | > But one other suggestion, that of putting the declaration in the switch, as > in "switch(int c = foo.bar().baz().fred().wilma().barney())", suggests the > notion that a declaration with an initializer is an expression with a value. > That might be worth thinking about. Yes I like that idea... but most of the time you wouldn't want to declare variables inside a complex expression. I suppose their scope would usually just be the scope of the statement. Sean |
March 28, 2002 Re: Suggestion: way to get switch() value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <spalmer@iname.com> wrote in message news:a7vt2l$10ac$1@digitaldaemon.com... > > But one other suggestion, that of putting the declaration in the switch, > as > > in "switch(int c = foo.bar().baz().fred().wilma().barney())", suggests the > > notion that a declaration with an initializer is an expression with a > value. > > That might be worth thinking about. > > Yes I like that idea... but most of the time you wouldn't want to declare variables inside a complex expression. I suppose their scope would usually just be the scope of the statement. I think I'd prefer that it have the same scope as if the declaration came in the immediately preceeding statement. { int a; // ... b not visible here... a = (int b = c * 5); // b visible here, and extends to closing brace. } -- Richard Krehbiel, Arlington, VA, USA rich@kastle.com (work) or krehbiel3@comcast.net (personal) |
March 28, 2002 Re: Suggestion: way to get switch() value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <spalmer@iname.com> wrote in message news:a7vsn9$1076$1@digitaldaemon.com... > I just can't see why you can't merely do this: > > int myVar = foo.bar().baz().fred().wilma().barney(); > switch (myVar) Because myVar will now be clattering the namespace, while it's only needed _inside_ the switch (like in most cases the loop counter is only needed inside the loop). Of course, an additional pair of braces could be added... but it is a hack. |
April 23, 2002 Re: Suggestion: way to get switch() value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <spalmer@iname.com> wrote in message news:a7vsn9$1076$1@digitaldaemon.com... > The only thing this thread does for me is make me want the old Pascal 'with' > statement. Even that had some flaws. I wasn't aware that D had a with statement. I should go look that up. I'll save you the trouble <g>. D has a with statement. To tell the truth, I'm not that sure it's a good idea, but it is there. |
April 23, 2002 Re: Suggestion: way to get switch() value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:aa336i$274n$1@digitaldaemon.com... > I'll save you the trouble <g>. D has a with statement. To tell the truth, I'm not that sure it's a good idea, but it is there. It is a good idea. I even think it would be better if it worked with structures too, especially when filling large WinAPI structs (WNDCLASS, LOGFONT etc). |
April 24, 2002 Re: Suggestion: way to get switch() value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:aa3lsj$2rhv$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:aa336i$274n$1@digitaldaemon.com... > > I'll save you the trouble <g>. D has a with statement. To tell the truth, > > I'm not that sure it's a good idea, but it is there. > It is a good idea. I even think it would be better if it worked with structures too, especially when filling large WinAPI structs (WNDCLASS, LOGFONT etc). That's a good idea. -Walter |
Copyright © 1999-2021 by the D Language Foundation