[DGD] Invalid ranges...

Troels Therkelsen troels at 2-10.org
Mon Oct 22 17:58:41 CEST 2001


> [...]
> > why doesn't it work for range underflow:
> >
> >   ({1, 2, 3})[-1..0] == error
> 
> Oh, but it does:
> 
>     ({ 1, 2, 3 })[0 .. -1] == ({ })
> 
> So the two special cases are [0 .. 0-1] and [size .. size-1], and the
> general case is [x .. x-1] == ({ }), for 0 <= x <= size.  To be
> consistent with normal ranges, xxx[-1 .. 0] would have to be an array
> of <two> elements, if it worked at all.
> 
> I'm sorry that you think this is kludgy.  Personally, I think that
> returning ({ }) for any invalid range is dangerous, <unless> ({ }) and
> ([ ]) were somehow equivalent with nil -- which is something that many
> have requested for the sake of convenience, but actually, LPC is a more
> expressive language with that distinction.
> 
> Regards,
> Dworkin

I don't think that it's a kludge that a[x..(sizeof(a))] and a[x..(0 - 1)]
works, I guess I'm just having troubles seeing the finer points in why the
working invalid ranges should be restricted to those two.  Like I said in
my previous post, I can learn to work around it... I actually only found
it because of buggy code, so I suppose that does support your claim that
allowing any invalid range is dangerous =) (I had [-1..0] instead
of [0..-1]).

Anyway, I'm slowly learning DGD, and I appreciate the comments from
people, they are very educational :)

Thanks,

/Troels Therkelsen


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



More information about the DGD mailing list