Operator overhaul

Russell Lewis webmaster at villagersonline.com
Thu Oct 23 10:43:21 PDT 2008


Sergey Gromov wrote:
> Wed, 22 Oct 2008 21:22:09 -0700,
> Russell Lewis wrote:
>>> Any other operator-related issues?
>> While we're at it, we need to think about lazy slicing (with $).  Say 
>> that you have an lazy array type (where it only generates the members 
>> when required).  In that sort of situation, you don't necessarily want 
>> to generate the entire array (so that you can calculate the length) the 
>> first time that somebody does
>> 	a = a[0..$-1];
>> or
>> 	tmp = a[$-1];
>>
>> You want to be able to keep a reference that says "so many characters 
>> from the end of the array, though the length of the array isn't known yet."
> 
> If you have a lazy array, its opSlice(size_t, size_t) can return another 
> lazy array, properly configured.  What's the problem?

The problem is that when you have an opSlice which isn't $-aware, the code
	a = a[0..$-1];
gets converted by the compiler into
	a = a[0..a.length-1];
which, of course, means that our array isn't lazy anymore.

Ideally, opSlice should have variants which allow the data structure to 
say "I will remember to never return you the last few elements" without 
having to calculate the array length at slice-time.



More information about the Digitalmars-d mailing list