June 30, 2004
On Tue, 29 Jun 2004 13:15:33 +0000 (UTC), pragma <EricAnderton at yahoo dot com pragma_member@pathlink.com> wrote:
> In article <cbr6l0$rj5$1@digitaldaemon.com>, Arcane Jill says...
>>
>>
>> #    delete a[n];
>>
>> This only works for ASSOCIATIVE arrays. For other types of array, it will call
>> the element's destructor.
>>
>> Actually, this non-standard use of delete is dead confusing. I'd prefer a new
>> keyword (remove). In such a scheme, we could have:
>>
>> #    // For associative arrays
>> #    remove a[n];  // remove the key n and its associated value from the array a
>> #    delete a[n];  // call the destructor of a[n]
>>
>> and, even better...
>>
>> #    // For dynamic arrays
>> #    remove a[n];
>>
>> could be equivalent to:
>>
>> #    for (uint i=n+1; i<a.length; ++i)
>> #    {
>> #        a[n-1] = a[n];
>> #    }
>> #    a[a.length - 1] = null; // help the GC out
>> #    a.length = a.length - 1;
>>
>> That would be neat.
>> Arcane Jill
>
> While you're at it, wouldn't the following...
>
> #    remove a[m..n];
>
> ..work well for removing a slice from an array?

Hey cool.. I wonder what type m..n turns into exactly, if it was accessable to us then we could modify this:

extern (C) void *memmove( void *dest, void *src, size_t count );

template remove(T) {
	T remove(inout T a, uint i) {
		memmove(&a[i],&a[i+1],typeof(a[0]).sizeof*(a.length-i));
		a.length = a.length-1;
		return a;
	}
}

to remove the complete slice/range from the array.

> I've yearned for this kind of flexibility from arrays in a language for some
> time now.  I'd even settle for some standard array methods like '.remove(x)'
> '.clear()' or '.isEmpty()'.
>
> - Pragma
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 30, 2004
"Arcane Jill" <Arcane_member@pathlink.com> escribió en el mensaje
news:cbr6l0$rj5$1@digitaldaemon.com
| #    delete a[n];
|
| This only works for ASSOCIATIVE arrays. For other types of array, it will
call
| the element's destructor.
|
| Actually, this non-standard use of delete is dead confusing. I'd prefer a
new
| keyword (remove). In such a scheme, we could have:
|
| #    // For associative arrays
| #    remove a[n];  // remove the key n and its associated value from the
array a
| #    delete a[n];  // call the destructor of a[n]
|

Even it's been said to death, I agree (95%).

| and, even better...
|
| #    // For dynamic arrays
| #    remove a[n];
|
| could be equivalent to:
|
| #    for (uint i=n+1; i<a.length; ++i)
| #    {
| #        a[n-1] = a[n];
| #    }
| #    a[a.length - 1] = null; // help the GC out
| #    a.length = a.length - 1;
|
| That would be neat.

I tend to agree (60%).

| Arcane Jill

-----------------------
Carlos Santander Bernal


1 2 3
Next ›   Last »