Re: why does this crash?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Thanks Derek,
    I re-read the Reference Manual on subscripting and slicing
sequences. I knew 0 was a valid subscript, but I forgot that its only
if you're starting at 1 (i.e. my_seq[1..0] = {}). Like I said, its
late. In fact, as I'm respoding to this its 4:50am. I've just beek
pecking away at my computer all night. Time for bed.

~Greg


On Sat, 02 Oct 2004 21:20:11 -0700, Derek Parnell
<guest at rapideuphoria.com> wrote:
> 
> posted by: Derek Parnell <ddparnell at bigpond.com>
> 
> Greg Haberek wrote:
> >
> > Maybe its late, maybe I'm just too tired... I don't know whats wrong
> > with this code. I have *no idea* why this is crashing.
> 
> Because the first file you test does not have a slash in it. Thus 's'
> is set to zero, and 'd' is set to 4, the location of the dot.
> 
> This means that 'filename[d+1..s]' resolves to 'filename[5..0]' which
> is not a valid slice.
> 
> > Last time I
> > checked, d+1 = 5, not -4. Anyway, here's the code. Someone please test
> > it and tell me what I may or may not be doing wrong.
> 
> The length of the slice is calculated as ...
> 
>  end - start + 1
> 
> substituting the values in your code, we get ...
> 
>   0 - 5 + 1 = -4
> 
> Hope that helps.
> 
> By the way, you code might do better with ...
> 
>    if s then
>        out[2] = reverse( filename[d+1..s] )
>        out[1] = reverse( filename[s..length(filename)] )
>    else
>        out[2] = reverse( filename[d+1 .. length(filename)]
>        out[1] = ""
>    end if
> --
> Derek Parnell
> Melbourne, Australia
> 
> 
> 
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu