opDollar

Benji Smith dlanguage at benjismith.net
Fri Sep 12 11:54:59 PDT 2008


Stewart Gordon wrote:
> "Benji Smith" <dlanguage at benjismith.net> wrote in message 
> news:gacrn7$221v$1 at digitalmars.com...
> <snip>
>> Also, even when $ is a number, it isn't the index of the "end" node or 
>> the "last" element. It's the index *after* the last element.
>>
>> I think only "length" or "size" are accurate.
> 
> So you think that, in the case of a 3-based array type, $ should be the 
> index of the antepenultimate element?
> 
> Stewart.

I didn't say anything about what it *should* mean. I was just saying 
that it certainly doesn't refer to the last element.

I have mixed feelings about what $ should mean. In an array slice, it 
makes sense for $ to be the length, because slicing uses an open range 
on the right-hand side

    array[0..5] // selects elements 0 - 4
    array[5..$] // selects everything from 5 to the end

But I also think the $, when used alone in an array index, ought to 
refer to the last element:

    array[$] // ideally: selects the last element.

Of course, the way it really works right now is like this:

    array[$ - 1] // awkward: selects last element
    array[$] // out of bounds. access violation.

So, I'm not really sure what I want. Above all, I think $ should have a 
consistent meaning.

--benji


More information about the Digitalmars-d-announce mailing list