[DGD] Re: casting nil (another idea...)

Steve Wooster swooster at xprt.net
Wed Mar 24 00:21:51 CET 2004


At 10:19 PM 3/23/2004 +0000, you wrote:
>>From: Steve Wooster <swooster at xprt.net>
>>Heh, I'm still miffed that "test"[2..6] runtimes instead of returning 
>>"st". What I wouldn't give for a config option to change that...
>
>I'm not sure why you'd want that, when you can simply type "st" and be 
>done with it... it would still be a constant in either form. The only way 
>to achieve your idea in a way that wouldn't compromise efficiency would be 
>to have "test"[2..6] detected as a preprocessor operation, converting it 
>to "st" before compilation. But this is absurd for obvious reasons. And 
>performing an operation on a constant during execution time wouldn't make 
>any sense at all. So this idea really baffles me... are you just a lazy 
>typist? ; )

You're missing the point entirely... I was using the constant string to 
illustrate the type of behavior I wanted. In practice I wouldn't do that 
with a constant. I like to be able to do things like:

// Called when the player types "mycommand <various arguments>"
// assumes str != nil
int _mycommand(string str)
{
     if (str[0..13]=="sub-command 1 ")
         code for sub-command 1;
     if (str[0..15]=="another command ")
         code for another sub-command;
     [etc... for many subcommands]
}

Having to test the length of the string before many of those checks is 
cumbersome at best. What Michael McKiel suggested is pretty good (and 
probably what I'll end up doing- thanks for the suggestion, Michael), but 
still nowhere as nice and succinct as str[a..b].

-Steve Wooster

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list