[DGD] Switch-Case Variable Scope

Kris Van Hees aedil at alchar.org
Thu Apr 18 15:43:57 CEST 2013


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.



More information about the DGD mailing list