[DGD] Switch-Case Variable Scope
Raymond Jennings
shentino at gmail.com
Thu Apr 18 18:14:01 CEST 2013
Indeed, especially if you can fall through a case label.
I think being able to do that forces this "case label scope" to require C++
style "declare a variable in the middle of a block" support to support your
suggestion.
On Thu, Apr 18, 2013 at 8:23 AM, Noah Gibbs <noah_gibbs at yahoo.com> wrote:
> All good. It's uncommon. C allows that too, though, which is probably
> why he considered it sorta-semi-obvious. That's where I originally saw it.
>
>
> ________________________________
> From: Blain <blain20 at gmail.com>
> To: All about DGD and Hydra <dgd at dworkin.nl>
> Sent: Thursday, April 18, 2013 7:06 AM
> Subject: Re: [DGD] Switch-Case Variable Scope
>
>
> Well, because this is the first time I've seen a block placed there! In
> all my years... I wonder if I missed this in other drivers too. Yup,
> LPMUD/Amylaar allows it. MudOS allows it without braces, which is where I
> was spoiled from. Even in LPMUD and LDMUD docs I'd never seen an example
> of using a block specifically with a case label. Thanks!
>
> Felix, please excuse my momentary lapse into noobery.
> On Apr 18, 2013 8:44 PM, "Kris Van Hees" <aedil at alchar.org> wrote:
>
> > Why would you not simply use:
> >
> > switch typeof(arg)) {
> > case T_ARRAY: {
> > mixed *ret;
> > <code>
> > break;
> > }
> > case T_MAPPING: {
> > mixed *ret;
> > <code>
> > break;
> > }
> > }
> >
> > A case label does not establish a local scope sice it is not a statement
> > block,
> > but it is very easy to encapsulate the statements in a statement block,
> and
> > thereby gain local scope to do what you want. No need to change the
> > language
> > syntax for that...
> >
> > Cheers,
> > Kris
> >
> > On Thu, Apr 18, 2013 at 08:36:05AM -0500, Blain wrote:
> > > Hey, Felix... I don't suppose you might not be totally averse to
> > > switch-case local variables, wouldya? The primary reason I prefer them
> > is
> > > for typechecking purposes. Other reasons amount to aesthetics only,
> > though.
> > >
> > > Here's what I would like to do with them in places where I'd like to
> make
> > > sure I sure I can get an error when I make a mistake with typing.
> > >
> > > switch(typeof(arg))
> > > {
> > > case T_ARRAY:
> > > mixed *ret;
> > >
> > > <code>
> > > break;
> > > cade T_MAPPING:
> > > mapping ret;
> > >
> > > <code>
> > > break;
> > > }
> > >
> > > Anyway, just a thought. I won't cry if you say no.
> > >
> > > *grin*
> > > -Blain
> > > ____________________________________________
> > > https://mail.dworkin.nl/mailman/listinfo/dgd
> >
> > --
> > Never underestimate a Mage with:
> > - the Intelligence to cast Magic Missile,
> > - the Constitution to survive the first hit, and
> > - the Dexterity to run fast enough to avoid being hit a second time.
> > ____________________________________________
> > https://mail.dworkin.nl/mailman/listinfo/dgd
> >
> ____________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd
> ____________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd
>
More information about the DGD
mailing list