September 12, 2008
> > Ok, so you want to change the meaning of $ altogether from being a number to something container dependent?
> 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.


	size is the size in bytes
	length is the number of elements
	norm is the length, darn.
September 12, 2008
Sclytrack wrote:
>>> Ok, so you want to change the meaning of $ altogether from being a
>>> number to something container dependent?
>> 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.
> 
> 
> 	size is the size in bytes
> 	length is the number of elements
> 	norm is the length, darn.

I like the sound of opTerminus as the function behind $

^^

A...
September 12, 2008
"Benji Smith" <dlanguage@benjismith.net> wrote in message news:gacrn7$221v$1@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.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies on the 'group where everybody may benefit. 

September 12, 2008
"Bill Baxter" wrote
> On Fri, Sep 12, 2008 at 11:10 AM, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
>> "Bill Baxter" wrote
>>> On Fri, Sep 12, 2008 at 2:28 AM, Steven Schveighoffer
>>>> For example, if you wanted to 'slice' an AA, you would use 2 keys for
>>>> the
>>>> slice 'indexes', what if the keys are strings?
>>>
>>> I'd say opSize, ala STL.  They got it right.  Should .size for arrays too, not .length.  "Size" is a word that generalizes pretty well, "length" is not.
>>
>> size doesn't work for slices that don't use sequential integers as index. i.e. imagine a sorted map (such as tree map) slice:
>>
>> TreeMap!(char[], char[]) tm;
>>
>> // create a slice of the treemap
>>
>> auto slice = tm["one".."two"];
>>
>> Replace the second with 'length' or 'size', and it looks weird:
>>
>> auto slice = tm["one"..length]
>> auto slice = tm["one"..size]
>>
>> I much prefer 'end' or 'last'.  It reads natural.  From the "one" element
>> to
>> the end.
>
> Ok, so you want to change the meaning of $ altogether from being a number to something container dependent?
>
> I guess that may generalize better...  But then shouldn't it evaluate to an iterator?  Argh! :-)

I think it should evaluate to the same type as you would specify as the first argument to the slice.  If that happens to be an integer, it's an integer, if it happens to be a string, it should be a string :)  If iterators are supported for a given container, it makes logical sense that slicing based on iterators should be supported.  I support slicing based on 'cursors,' which are basically iterators, in dcollections (well, only for ArrayList now, but I plan to do it for LinkedList and the tree types).

opLength/opSize implies that it should ALWAYS be an integer.  'sall I'm sayin.

-Steve


September 12, 2008
Stewart Gordon wrote:
> "Benji Smith" <dlanguage@benjismith.net> wrote in message news:gacrn7$221v$1@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
1 2
Next ›   Last »