[DGD] Switch-Case Variable Scope

Blain blain20 at gmail.com
Thu Apr 18 16:06:37 CEST 2013


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
>



More information about the DGD mailing list