Thread overview | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 29, 2004 [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
switch (qwert) {
case 1 {
yuiop = 3;
}
case 2 {
yuiop = 4;
}
case 3, 4, 5 {
yuiop = 5;
}
}
(Note no colons)
The idea:
- Having the case clauses as block statements seems the logical thing to me.
- Declarations/initialisations local to case clauses - I know you can do
case 1: {
Asdfg hjkl = new Asdfg;
// ...
} break;
but I still think my idea is neater.
- When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g.
switch (qwert) {
case 0, 5, 10 {
// do stuff if qwert is 0, 5 or 10
} else case 1..9 {
/* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
* (or should this be semi-inclusive like array
* slicing?)
*/
}
case 6..13 {
/* do stuff if qwert is 6..13, even if a
* previous case matched
*/
}
default {
// this would still mean do stuff if none match
}
}
Nesting could also be allowed, for a bit of syntactic sugar:
switch (qwert) {
case 0..10 {
// do something
case 4 {
// do something more specific
}
// now do something else
}
}
What do you think?
Stewart.
--
My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
|
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote: > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > switch (qwert) { > case 1 { > yuiop = 3; > } > case 2 { > yuiop = 4; > } > case 3, 4, 5 { > yuiop = 5; > } > } > > (Note no colons) > > The idea: > - Having the case clauses as block statements seems the logical thing to me. > > - Declarations/initialisations local to case clauses - I know you can do > > case 1: { > Asdfg hjkl = new Asdfg; > // ... > } break; > > but I still think my idea is neater. > > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > switch (qwert) { > case 0, 5, 10 { > // do stuff if qwert is 0, 5 or 10 > } else case 1..9 { > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > * (or should this be semi-inclusive like array > * slicing?) > */ > } > > case 6..13 { > /* do stuff if qwert is 6..13, even if a > * previous case matched > */ > } > > default { > // this would still mean do stuff if none match > } > } > > Nesting could also be allowed, for a bit of syntactic sugar: > > switch (qwert) { > case 0..10 { > // do something > > case 4 { > // do something more specific > } > > // now do something else > } > } > > What do you think? > > Stewart. > Oh no, not switch statements again. And this was my idea ;) -- -Anderson: http://badmama.com.au/~anderson/ |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | You could create an enhanced extended switch. Then you could have a basic switch for backward compatability and more complex power switch statement althogh the syntax and name could be slightly different. In article <bvb6lc$1t7a$1@digitaldaemon.com>, Stewart Gordon says... > >In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > switch (qwert) { > case 1 { > yuiop = 3; > } > case 2 { > yuiop = 4; > } > case 3, 4, 5 { > yuiop = 5; > } > } > >(Note no colons) > >The idea: >- Having the case clauses as block statements seems the logical thing to me. > >- Declarations/initialisations local to case clauses - I know you can do > > case 1: { > Asdfg hjkl = new Asdfg; > // ... > } break; > >but I still think my idea is neater. > >- When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > switch (qwert) { > case 0, 5, 10 { > // do stuff if qwert is 0, 5 or 10 > } else case 1..9 { > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > * (or should this be semi-inclusive like array > * slicing?) > */ > } > > case 6..13 { > /* do stuff if qwert is 6..13, even if a > * previous case matched > */ > } > > default { > // this would still mean do stuff if none match > } > } > >Nesting could also be allowed, for a bit of syntactic sugar: > > switch (qwert) { > case 0..10 { > // do something > > case 4 { > // do something more specific > } > > // now do something else > } > } > >What do you think? > >Stewart. > >-- >My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | You could create an enhanced extended switch. Then you could have a basic switch for backward compatability and more complex power switch statement althogh the syntax and name could be slightly different. In article <bvb6lc$1t7a$1@digitaldaemon.com>, Stewart Gordon says... > >In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > switch (qwert) { > case 1 { > yuiop = 3; > } > case 2 { > yuiop = 4; > } > case 3, 4, 5 { > yuiop = 5; > } > } > >(Note no colons) > >The idea: >- Having the case clauses as block statements seems the logical thing to me. > >- Declarations/initialisations local to case clauses - I know you can do > > case 1: { > Asdfg hjkl = new Asdfg; > // ... > } break; > >but I still think my idea is neater. > >- When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > switch (qwert) { > case 0, 5, 10 { > // do stuff if qwert is 0, 5 or 10 > } else case 1..9 { > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > * (or should this be semi-inclusive like array > * slicing?) > */ > } > > case 6..13 { > /* do stuff if qwert is 6..13, even if a > * previous case matched > */ > } > > default { > // this would still mean do stuff if none match > } > } > >Nesting could also be allowed, for a bit of syntactic sugar: > > switch (qwert) { > case 0..10 { > // do something > > case 4 { > // do something more specific > } > > // now do something else > } > } > >What do you think? > >Stewart. > >-- >My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | Why do people put thier responses at the bottom :P. All that scrolling makes me dizzy. C "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bvb7ip$1umk$2@digitaldaemon.com... > Stewart Gordon wrote: > > > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > > > switch (qwert) { > > case 1 { > > yuiop = 3; > > } > > case 2 { > > yuiop = 4; > > } > > case 3, 4, 5 { > > yuiop = 5; > > } > > } > > > > (Note no colons) > > > > The idea: > > - Having the case clauses as block statements seems the logical thing > > to me. > > > > - Declarations/initialisations local to case clauses - I know you can do > > > > case 1: { > > Asdfg hjkl = new Asdfg; > > // ... > > } break; > > > > but I still think my idea is neater. > > > > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > > > switch (qwert) { > > case 0, 5, 10 { > > // do stuff if qwert is 0, 5 or 10 > > } else case 1..9 { > > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > > * (or should this be semi-inclusive like array > > * slicing?) > > */ > > } > > > > case 6..13 { > > /* do stuff if qwert is 6..13, even if a > > * previous case matched > > */ > > } > > > > default { > > // this would still mean do stuff if none match > > } > > } > > > > Nesting could also be allowed, for a bit of syntactic sugar: > > > > switch (qwert) { > > case 0..10 { > > // do something > > > > case 4 { > > // do something more specific > > } > > > > // now do something else > > } > > } > > > > What do you think? > > > > Stewart. > > > > Oh no, not switch statements again. And this was my idea ;) > > -- > -Anderson: http://badmama.com.au/~anderson/ |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | I like that idea.
I would make it an more generic expression instead of an block
then you could write:
switch (qwert)
{
case 1 foo();
case 2
{
foo2();
}
}
Stewart Gordon wrote:
> In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases:
>
> switch (qwert) {
> case 1 {
> yuiop = 3;
> }
> case 2 {
> yuiop = 4;
> }
> case 3, 4, 5 {
> yuiop = 5;
> }
> }
>
> (Note no colons)
>
> The idea:
> - Having the case clauses as block statements seems the logical thing to me.
>
> - Declarations/initialisations local to case clauses - I know you can do
>
> case 1: {
> Asdfg hjkl = new Asdfg;
> // ...
> } break;
>
> but I still think my idea is neater.
>
> - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g.
>
> switch (qwert) {
> case 0, 5, 10 {
> // do stuff if qwert is 0, 5 or 10
> } else case 1..9 {
> /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9
> * (or should this be semi-inclusive like array
> * slicing?)
> */
> }
>
> case 6..13 {
> /* do stuff if qwert is 6..13, even if a
> * previous case matched
> */
> }
>
> default {
> // this would still mean do stuff if none match
> }
> }
>
> Nesting could also be allowed, for a bit of syntactic sugar:
>
> switch (qwert) {
> case 0..10 {
> // do something
>
> case 4 {
> // do something more specific
> }
>
> // now do something else
> }
> }
>
> What do you think?
>
> Stewart.
>
|
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | I think that you've assumed that everyone writes with the egregious K&R bracing, and that your proposal relies on that for digestibility. "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:bvb6lc$1t7a$1@digitaldaemon.com... > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > switch (qwert) { > case 1 { > yuiop = 3; > } > case 2 { > yuiop = 4; > } > case 3, 4, 5 { > yuiop = 5; > } > } > > (Note no colons) > > The idea: > - Having the case clauses as block statements seems the logical thing to me. > > - Declarations/initialisations local to case clauses - I know you can do > > case 1: { > Asdfg hjkl = new Asdfg; > // ... > } break; > > but I still think my idea is neater. > > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > switch (qwert) { > case 0, 5, 10 { > // do stuff if qwert is 0, 5 or 10 > } else case 1..9 { > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > * (or should this be semi-inclusive like array > * slicing?) > */ > } > > case 6..13 { > /* do stuff if qwert is 6..13, even if a > * previous case matched > */ > } > > default { > // this would still mean do stuff if none match > } > } > > Nesting could also be allowed, for a bit of syntactic sugar: > > switch (qwert) { > case 0..10 { > // do something > > case 4 { > // do something more specific > } > > // now do something else > } > } > > What do you think? > > Stewart. > > -- > My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to C | "C" <dont@respond.com> wrote in message news:bvbp1d$2rji$1@digitaldaemon.com... > Why do people put thier responses at the bottom :P. All that scrolling makes me dizzy. > > C > "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message > news:bvb7ip$1umk$2@digitaldaemon.com... > > Stewart Gordon wrote: > > > > > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > > > > > switch (qwert) { > > > case 1 { > > > yuiop = 3; > > > } > > > case 2 { > > > yuiop = 4; > > > } > > > case 3, 4, 5 { > > > yuiop = 5; > > > } > > > } > > > > > > (Note no colons) > > > > > > The idea: > > > - Having the case clauses as block statements seems the logical thing > > > to me. > > > > > > - Declarations/initialisations local to case clauses - I know you can do > > > > > > case 1: { > > > Asdfg hjkl = new Asdfg; > > > // ... > > > } break; > > > > > > but I still think my idea is neater. > > > > > > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > > > > > switch (qwert) { > > > case 0, 5, 10 { > > > // do stuff if qwert is 0, 5 or 10 > > > } else case 1..9 { > > > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > > > * (or should this be semi-inclusive like array > > > * slicing?) > > > */ > > > } > > > > > > case 6..13 { > > > /* do stuff if qwert is 6..13, even if a > > > * previous case matched > > > */ > > > } > > > > > > default { > > > // this would still mean do stuff if none match > > > } > > > } > > > > > > Nesting could also be allowed, for a bit of syntactic sugar: > > > > > > switch (qwert) { > > > case 0..10 { > > > // do something > > > > > > case 4 { > > > // do something more specific > > > } > > > > > > // now do something else > > > } > > > } > > > > > > What do you think? > > > > > > Stewart. > > > > > > > Oh no, not switch statements again. And this was my idea ;) > > > > -- > > -Anderson: http://badmama.com.au/~anderson/ I agree! |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan Wienczny | A parsing nightmare, surely! "Stephan Wienczny" <wienczny@web.de> wrote in message news:bvbtok$2h7$1@digitaldaemon.com... > I like that idea. > I would make it an more generic expression instead of an block > then you could write: > > switch (qwert) > { > case 1 foo(); > > case 2 > { > foo2(); > } > } > > > Stewart Gordon wrote: > > In line with the multiple syntaxes for align and member access keywords, it would make sense to have this syntax for cases: > > > > switch (qwert) { > > case 1 { > > yuiop = 3; > > } > > case 2 { > > yuiop = 4; > > } > > case 3, 4, 5 { > > yuiop = 5; > > } > > } > > > > (Note no colons) > > > > The idea: > > - Having the case clauses as block statements seems the logical thing to > > me. > > > > - Declarations/initialisations local to case clauses - I know you can do > > > > case 1: { > > Asdfg hjkl = new Asdfg; > > // ... > > } break; > > > > but I still think my idea is neater. > > > > - When this syntax is used, there would be no default fall-through - it would simply execute the block specified by the parameter. Further, it could be permissible for cases to overlap, in which case (NPI) all would be executed. Maybe an 'else' could be used to override this, e.g. > > > > switch (qwert) { > > case 0, 5, 10 { > > // do stuff if qwert is 0, 5 or 10 > > } else case 1..9 { > > /* do stuff if qwert is 1, 2, 3, 4, 6, 7, 8 or 9 > > * (or should this be semi-inclusive like array > > * slicing?) > > */ > > } > > > > case 6..13 { > > /* do stuff if qwert is 6..13, even if a > > * previous case matched > > */ > > } > > > > default { > > // this would still mean do stuff if none match > > } > > } > > > > Nesting could also be allowed, for a bit of syntactic sugar: > > > > switch (qwert) { > > case 0..10 { > > // do something > > > > case 4 { > > // do something more specific > > } > > > > // now do something else > > } > > } > > > > What do you think? > > > > Stewart. > > > |
January 29, 2004 Re: [Suggestion] Alternative switch/case syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | Matthew wrote:
> A parsing nightmare, surely!
No, not necessarily. But type ocassionally that extra : as used to from C and you spoil it - thus this syntax is unstable to use. So i'd be against it.
-eye
|
Copyright © 1999-2021 by the D Language Foundation