> 2002-12-05 10:45:39, Michael G Schwern <[EMAIL PROTECTED]> wrote:
> I'm going to ask something that's probably going to launch off into a 
> long, silly thread. But I'm really curious what the results will be so 
> I'll ask it anyway. Think of it as an experiment.
> 
> So here's your essay topic:
> 
> Explain how having indexes (arrays, substr, etc...) in Perl 6 start at 0 
> will benefit most users. Do not invoke legacy. [1]
> 
> [1] ie. "because that's how most other languages do it" or "everyone is 
> used to it by now" are not valid arguments. Ask any Pascal programmer. 
> :)


The other (reverse) way out, i'm not trying to make an essay, just think 
out loud but if you have $string = "Hello World", and you want the last 
three chars, you do:

        $wanted = substr $string, -3;

If the first index was 1, it could be ok too, but what would be offset 
0? What if someone was looking at his string backwards?

        $pos   = 1;                 #  0  |  1
                                    # ---------
        substr $string, $pos--, 1;  # 'H' | 'e'
        substr $string, $pos--, 1;  # 'd' | 'H'
        substr $string, $pos--, 1;  # 'l' | ''  ?
        substr $string, $pos--, 1;  # 'r' | 'd' ?


Dont ask me why someone would do that... But i expect to get the last 
$string's char with $pos == -1, not 0.

I also find the 'offset' idea to be consistent with binary math. After 
all, with bytes, 0x7F + 1 == +0d127 but also -0d128... and i found it 
sometimes useful to be able to mix signed and unsigned values.

One could argue it's not the way to go, it's tricky, you dont mix
signed/unsigned... blah. Walking is tricky, bicycling is tricky,
remember the first time you tried and you fell?

blah. no more args :-)
(yet another lurker)



Reply via email to