Jump to page: 1 2 3
Thread overview
delete hash[key] deprecated???
Feb 11, 2008
Leandro Lucarella
Feb 11, 2008
Leandro Lucarella
Jul 15, 2008
Stewart Gordon
Jul 15, 2008
Leandro Lucarella
Jul 15, 2008
Max Samukha
Jul 15, 2008
Leandro Lucarella
Jul 15, 2008
Koroskin Denis
Jul 16, 2008
Max Samukha
Jul 16, 2008
JAnderson
Jul 16, 2008
Regan Heath
Jul 18, 2008
Simen Kjaeraas
Jul 18, 2008
Stewart Gordon
Jul 19, 2008
Max Samukha
Jul 19, 2008
Max Samukha
Jul 19, 2008
Stewart Gordon
Jul 19, 2008
Koroskin Denis
Jul 19, 2008
Stewart Gordon
Jul 19, 2008
Koroskin Denis
Jul 19, 2008
JAnderson
Jul 20, 2008
Leandro Lucarella
Jul 20, 2008
Max Samukha
Jul 16, 2008
Moritz Warning
Feb 11, 2008
BCS
Feb 11, 2008
Leandro Lucarella
Feb 12, 2008
Robert Fraser
Jul 15, 2008
Stewart Gordon
February 11, 2008
I have this example code:

class C { ... }

C[string] hash;

auto c = new C;
hash["x"] = c;

// other place
delete hash["x"];
hash.remove("x");

And I got: Error: delete aa[key] deprecated, use aa.remove(key)

I don't want to remove the element of the array, I want to destroy the
object stored at key "x". Does hash.remove("x") remove the item from the
hash *and* delete c? I found that a little odd. If not, do I have to do:
auto c = hash["x"];
hash.remove["x"];
delete c;

I find that a little odd too.

And yes, I want to explicitly delete the object because I want to minimize the GC activity since my program is kinda RT :)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Peperino nos enseña que debemos ofrendirnos con ofrendas de vino si
queremos obtener la recompensa de la parte del medio del vacío.
	-- Peperino Pómoro
February 11, 2008
"Leandro Lucarella" <llucax@gmail.com> wrote in message news:20080211130722.GA18729@burns.springfield.home...

> And I got: Error: delete aa[key] deprecated, use aa.remove(key)

As the error suggests, the first syntax was used before the second was introduced.  The funny thing is, the 'remove' syntax was partially introduced to allow exactly what you're trying to do.  X(

> I don't want to remove the element of the array, I want to destroy the object stored at key "x". Does hash.remove("x") remove the item from the hash *and* delete c?

No.

> If not, do I have to do:
> auto c = hash["x"];
> hash.remove["x"];
> delete c;

Yeah, you do.


February 11, 2008
Jarrett Billingsley, el 11 de febrero a las 08:50 me escribiste:
> "Leandro Lucarella" <llucax@gmail.com> wrote in message news:20080211130722.GA18729@burns.springfield.home...
> 
> > And I got: Error: delete aa[key] deprecated, use aa.remove(key)
> 
> As the error suggests, the first syntax was used before the second was introduced.  The funny thing is, the 'remove' syntax was partially introduced to allow exactly what you're trying to do.  X(
> 
> > I don't want to remove the element of the array, I want to destroy the object stored at key "x". Does hash.remove("x") remove the item from the hash *and* delete c?
> 
> No.
> 
> > If not, do I have to do:
> > auto c = hash["x"];
> > hash.remove["x"];
> > delete c;
> 
> Yeah, you do.

Ugly :(

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
You are the very reason why everything happens to you
February 11, 2008
Reply to Leandro,

> I have this example code:
> 
> class C { ... }
> 
> C[string] hash;
> 
> auto c = new C;
> hash["x"] = c;
> // other place
> delete hash["x"];
> hash.remove("x");
> And I got: Error: delete aa[key] deprecated, use aa.remove(key)
> 
> I don't want to remove the element of the array, I want to destroy the
> object stored at key "x". Does hash.remove("x") remove the item from
> the
> hash *and* delete c? I found that a little odd. If not, do I have to
> do:
> auto c = hash["x"];
> hash.remove["x"];
> delete c;
> I find that a little odd too.
> 
> And yes, I want to explicitly delete the object because I want to
> minimize the GC activity since my program is kinda RT :)
> 

you might have luck with "delete (hash["x"]);" but I to lazy to check.


February 11, 2008
BCS, el 11 de febrero a las 20:23 me escribiste:
> Reply to Leandro,
> 
> >I have this example code:
> >class C { ... }
> >C[string] hash;
> >auto c = new C;
> >hash["x"] = c;
> >// other place
> >delete hash["x"];
> >hash.remove("x");
> >And I got: Error: delete aa[key] deprecated, use aa.remove(key)
> >I don't want to remove the element of the array, I want to destroy the
> >object stored at key "x". Does hash.remove("x") remove the item from
> >the
> >hash *and* delete c? I found that a little odd. If not, do I have to
> >do:
> >auto c = hash["x"];
> >hash.remove["x"];
> >delete c;
> >I find that a little odd too.
> >And yes, I want to explicitly delete the object because I want to
> >minimize the GC activity since my program is kinda RT :)
> 
> you might have luck with "delete (hash["x"]);" but I to lazy to check.

I tried and I failed :(

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Pity's very underrated. I like pity. It's good.
	-- George Constanza
February 12, 2008
Leandro Lucarella wrote:
> I have this example code:
> 
> class C { ... }
> 
> C[string] hash;
> 
> auto c = new C;
> hash["x"] = c;
> 
> // other place
> delete hash["x"];
> hash.remove("x");
> 
> And I got: Error: delete aa[key] deprecated, use aa.remove(key)
> 
> I don't want to remove the element of the array, I want to destroy the
> object stored at key "x". Does hash.remove("x") remove the item from the
> hash *and* delete c? I found that a little odd. If not, do I have to do:
> auto c = hash["x"];
> hash.remove["x"];
> delete c;
> 
> I find that a little odd too.
> 
> And yes, I want to explicitly delete the object because I want to minimize
> the GC activity since my program is kinda RT :)
> 
I see another, much bigger, problem with "delete hash[x]" meaning "hash.remove(x)" that goes against the D philosophy. One of the most important things about D is that it is generally unambiguously parsed without requiring semantic analysis. However, this is not so in the case of a DeleteExp, which can either actually refer to a delete expression or a function call. In other words, there are two semantic entities for things that are syntactically identical (in that case "delete [expression]"), and the effect of that depends not on the expression itself, but, in fact, only a piece of the expression.

Someone correct me if I'm misjudging this.
February 12, 2008
"Robert Fraser" <fraserofthenight@gmail.com> wrote in message news:for70f$2vf0$1@digitalmars.com...

> I see another, much bigger, problem with "delete hash[x]" meaning "hash.remove(x)" that goes against the D philosophy. One of the most important things about D is that it is generally unambiguously parsed without requiring semantic analysis. However, this is not so in the case of a DeleteExp, which can either actually refer to a delete expression or a function call. In other words, there are two semantic entities for things that are syntactically identical (in that case "delete [expression]"), and the effect of that depends not on the expression itself, but, in fact, only a piece of the expression.
>
> Someone correct me if I'm misjudging this.

The "delete aa[x]" syntax to mean "remove the key x from aa" was deprecated in 0.126, that is, June of 2005, for the exact reasons you mention.  Hence the "deprecated" error message.  That the "deprecated" error message has not yet been removed after two and a half years seems to me more of an oversight than anything else.


July 15, 2008
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:for9g5$2q7$1@digitalmars.com...
<snip>
> The "delete aa[x]" syntax to mean "remove the key x from aa" was deprecated in 0.126, that is, June of 2005, for the exact reasons you mention.  Hence the "deprecated" error message.  That the "deprecated" error message has not yet been removed after two and a half years seems to me more of an oversight than anything else.


Why should this means of removing an AA element have been de-deprecated?

If OTOH, you meant that it should have been redefined by now to delete the object, then maybe....

Stewart.

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

July 15, 2008
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:fopjrt$1b2c$1@digitalmars.com...
<snip>
>> If not, do I have to do:
>> auto c = hash["x"];
>> hash.remove["x"];
>> delete c;
>
> Yeah, you do.


No I don't.

   delete * cast(Object*) &hash["x"];

Test code:
----------
import std.stdio;

class Test {
   ~this() { writefln("Object destroyed"); }
}

void main() {
   Test[int] aa;

   aa[42] = new Test;
   delete * cast(Object*) &aa[42];
   writefln(42 in aa);
}
----------

The last statement is as much to show that it is actually deleted there and then as to show that it suppresses removal of the AA key.

Stewart.

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

July 15, 2008
"Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:g5gq00$2jfu$1@digitalmars.com...
> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message
> news:for9g5$2q7$1@digitalmars.com...
> <snip>
>> The "delete aa[x]" syntax to mean "remove the key x from aa" was deprecated in 0.126, that is, June of 2005, for the exact reasons you mention.  Hence the "deprecated" error message.  That the "deprecated" error message has not yet been removed after two and a half years seems to me more of an oversight than anything else.
>
>
> Why should this means of removing an AA element have been de-deprecated?
>
> If OTOH, you meant that it should have been redefined by now to delete the object, then maybe....

Yes, that's what I mean.  It doesn't make sense for a questionable design decision that was removed a year and a half before the language went 1.0 to prevent you from doing something completely reasonable today.


« First   ‹ Prev
1 2 3