Why I Use D

Simen Kjaeraas simen.kjaras at gmail.com
Fri Apr 11 08:58:33 PDT 2008


On Fri, 11 Apr 2008 09:45:26 +0200, Scott S. McCoy <tag at cpan.org> wrote:

> The same thing foo[$-3] is now.
>
> Whatever the heck that is.
>
> :-)
>
>
> On Mon, 2008-03-31 at 01:55 +0200, Simen Kjaeraas wrote:
>> On Mon, 31 Mar 2008 00:26:10 +0200, Scott S. McCoy <tag at cpan.org> wrote:
>>
>> > You also could if array[5 .. -3] implied length -3.
>> >
>> > Similarly. array[-3] could imply array[array.length -3]...
>> >
>> > But someone suggested against that, atleast for non-compile time
>> > checking.  I would agree, for the non-literal instance that a negative
>> > integer of -5 shouldn't result in magical figuring out if the element
>> > needs to be pulled from the front or the back.  But the literal case
>> > adds expressiveness, I think.
>>
>> T[int] foo;
>>
>> What is foo[-3]?
>>
>> And user-defined types with overloaded opIndex and opSlice.
>> Should [-X] work differently for them?
>>
>> -- Simen

I see. So I have an associative array foo, with indices possibly being
negative (int is signed), and I can't reach those due to negative indices
being wrapped around. Hardly a good thing, IMO.

My point is, there may be reasons to want to use negative indices, and
implicit $ will make that hard. Unless you suggest that to avoid that, I
should use [$-$-3]?

-- Simen



More information about the Digitalmars-d mailing list