digitalmars.D.learn - delete hash[key] deprecated???
- Leandro Lucarella (26/26) Feb 11 2008 I have this example code:
- Jarrett Billingsley (7/15) Feb 11 2008 As the error suggests, the first syntax was used before the second was
- Leandro Lucarella (8/29) Feb 11 2008 Ugly :(
-
Stewart Gordon
(24/29)
Jul 14 2008
"Jarrett Billingsley"
wrote in message - Leandro Lucarella (9/23) Jul 15 2008 Phew! That's much better! (!) o_O
- Max Samukha (4/20) Jul 15 2008 An alternative hack:
- Leandro Lucarella (8/25) Jul 15 2008 It just gets better and better ;)
- Koroskin Denis (5/24) Jul 15 2008 But you still have to remove a dead pointer from a collection:
- Max Samukha (14/17) Jul 15 2008 If 'remove' was modified to return the removed value, more compact
- JAnderson (3/27) Jul 15 2008 I think this is a good idea.
- Regan Heath (3/30) Jul 16 2008 Seconded!
- Simen Kjaeraas (3/32) Jul 18 2008 Thirded!
-
Stewart Gordon
(10/13)
Jul 18 2008
"Max Samukha"
wrote in message - Max Samukha (10/21) Jul 19 2008 Three options:
- Max Samukha (3/19) Jul 19 2008 I meant four options.
- Stewart Gordon (16/39) Jul 19 2008 And do what if the program wasn't built with a "debug switch"? Moreover...
- Koroskin Denis (14/17) Jul 19 2008 It doesn't return anything now.
- Stewart Gordon (10/22) Jul 19 2008 Are you missing my point, or guessing what Max meant?
- Koroskin Denis (8/13) Jul 19 2008 Hmm.. I missed that. At first, I though than remove() behaviour should b...
- JAnderson (9/38) Jul 19 2008 I think the compiler should remove the extra delete so that writing
- Leandro Lucarella (14/45) Jul 19 2008 If the idea was to add an assert in the remove code, I guess he meant no...
- Max Samukha (12/51) Jul 19 2008 I agree, "debug switch" is BS. What I meant is non-release builds.
- Moritz Warning (16/36) Jul 16 2008 FWIW:
- BCS (2/28) Feb 11 2008 you might have luck with "delete (hash["x"]);" but I to lazy to check.
- Leandro Lucarella (9/33) Feb 11 2008 I tried and I failed :(
- Robert Fraser (11/38) Feb 11 2008 I see another, much bigger, problem with "delete hash[x]" meaning
- Jarrett Billingsley (7/17) Feb 11 2008 The "delete aa[x]" syntax to mean "remove the key x from aa" was depreca...
-
Stewart Gordon
(10/15)
Jul 14 2008
"Jarrett Billingsley"
wrote in message - Jarrett Billingsley (5/16) Jul 14 2008 Yes, that's what I mean. It doesn't make sense for a questionable desig...
- Era Scarecrow (3/42) Jul 19 2008 I'm always interested in using more compact and more general versions o...
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
Feb 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.
Feb 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...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 youAnd 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.
Feb 11 2008
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:fopjrt$1b2c$1 digitalmars.com... <snip>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.If not, do I have to do: auto c = hash["x"]; hash.remove["x"]; delete c;Yeah, you do.
Jul 14 2008
Stewart Gordon, el 15 de julio a las 01:14 me escribiste:"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:fopjrt$1b2c$1 digitalmars.com... <snip>Phew! That's much better! (!) o_O -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- More people die from a champagne-cork popping, than from poison spidersNo I don't. delete * cast(Object*) &hash["x"];If not, do I have to do: auto c = hash["x"]; hash.remove["x"]; delete c;Yeah, you do.
Jul 15 2008
On Tue, 15 Jul 2008 11:13:33 -0300, Leandro Lucarella <llucax gmail.com> wrote:Stewart Gordon, el 15 de julio a las 01:14 me escribiste:An alternative hack: delete *("x" in hash);"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:fopjrt$1b2c$1 digitalmars.com... <snip>Phew! That's much better! (!) o_ONo I don't. delete * cast(Object*) &hash["x"];If not, do I have to do: auto c = hash["x"]; hash.remove["x"]; delete c;Yeah, you do.
Jul 15 2008
Max Samukha, el 15 de julio a las 17:54 me escribiste:It just gets better and better ;) -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- 22% of the time a pizza will arrive faster than an ambulance in Great-BritainAn alternative hack: delete *("x" in hash);Phew! That's much better! (!) o_ONo I don't. delete * cast(Object*) &hash["x"];If not, do I have to do: auto c = hash["x"]; hash.remove["x"]; delete c;Yeah, you do.
Jul 15 2008
On Tue, 15 Jul 2008 20:40:07 +0400, Leandro Lucarella <llucax gmail.com> wrote:Max Samukha, el 15 de julio a las 17:54 me escribiste:But you still have to remove a dead pointer from a collection: delete *("x" in hash); hash.remove("x");It just gets better and better ;)An alternative hack: delete *("x" in hash);Phew! That's much better! (!) o_ONo I don't. delete * cast(Object*) &hash["x"];If not, do I have to do: auto c = hash["x"]; hash.remove["x"]; delete c;Yeah, you do.
Jul 15 2008
On Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis" <2korden+dmd gmail.com> wrote:But you still have to remove a dead pointer from a collection: delete *("x" in hash); hash.remove("x");If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x"); Also, there would be no need to search for the value twice and introduce a temporary when the removed value is needed for further processing: // do something with the value, for example, pass it to a function foo(hash.remove("x")); instead of: auto v = hash["x"]; hash.remove("x"); foo(v);
Jul 15 2008
Max Samukha wrote:On Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis" <2korden+dmd gmail.com> wrote:I think this is a good idea. -JoelBut you still have to remove a dead pointer from a collection: delete *("x" in hash); hash.remove("x");If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x"); Also, there would be no need to search for the value twice and introduce a temporary when the removed value is needed for further processing: // do something with the value, for example, pass it to a function foo(hash.remove("x")); instead of: auto v = hash["x"]; hash.remove("x"); foo(v);
Jul 15 2008
JAnderson wrote:Max Samukha wrote:Seconded! Regan HeathOn Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis" <2korden+dmd gmail.com> wrote:I think this is a good idea.But you still have to remove a dead pointer from a collection: delete *("x" in hash); hash.remove("x");If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x"); Also, there would be no need to search for the value twice and introduce a temporary when the removed value is needed for further processing: // do something with the value, for example, pass it to a function foo(hash.remove("x")); instead of: auto v = hash["x"]; hash.remove("x"); foo(v);
Jul 16 2008
Regan Heath <regan netmail.co.nz> wrote:JAnderson wrote:Thirded! -- SimenMax Samukha wrote:Seconded! Regan HeathOn Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis" <2korden+dmd gmail.com> wrote:I think this is a good idea.But you still have to remove a dead pointer from a collection: delete *("x" in hash); hash.remove("x");If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x"); Also, there would be no need to search for the value twice and introduce a temporary when the removed value is needed for further processing: // do something with the value, for example, pass it to a function foo(hash.remove("x")); instead of: auto v = hash["x"]; hash.remove("x"); foo(v);
Jul 18 2008
"Max Samukha" <samukha voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m 4ax.com... <snip>If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x");<snip> And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception? Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Jul 18 2008
On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon" <smjg_1998 yahoo.com> wrote:"Max Samukha" <samukha voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m 4ax.com... <snip>Three options: 1. Throw an assert exception if the program was built with a debug switch 2. Always throw an exception 3. Make 'remove' return a pointer to the value 4. Continue silently I prefer the first option. Option 4 (current semantics) is the least acceptible, in my opinion.If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x");<snip> And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception? Stewart.
Jul 19 2008
On Sat, 19 Jul 2008 10:35:01 +0300, Max Samukha <samukha voliacable.com.removethis> wrote:On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon" <smjg_1998 yahoo.com> wrote:I meant four options."Max Samukha" <samukha voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m 4ax.com... <snip>Three options:If 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x");<snip> And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception? Stewart.
Jul 19 2008
"Max Samukha" <samukha voliacable.com.removethis> wrote in message news:d85384p9e1heua1f8f6vn2cesd9cosjlrc 4ax.com...On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon" <smjg_1998 yahoo.com> wrote:And do what if the program wasn't built with a "debug switch"? Moreover, I personally think that debug switches should be saved for programmer-defined debug code."Max Samukha" <samukha voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m 4ax.com... <snip>Three options: 1. Throw an assert exception if the program was built with a debug switchIf 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x");<snip> And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception? Stewart.2. Always throw an exception 3. Make 'remove' return a pointer to the valueAnd so if the key isn't present, return null. Hmm.... I guess it would be the programmer's responsibility not to keep lots of these pointers alive and thereby prevent the AA nodes from being GC'd. Hmm....4. Continue silentlyBut .remove has to return something. So how is this possible?I prefer the first option. Option 4 (current semantics) is the least acceptible, in my opinion.Hang on ... is 4 meant to be an option under the premise that we want .remove to return the removed value, or the option of not implementing this feature at all? Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Jul 19 2008
On Sat, 19 Jul 2008 16:39:18 +0400, Stewart Gordon <smjg_1998 yahoo.com> wrote:But .remove has to return something. So how is this possible?It doesn't return anything now.And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception?I think returning null is ok. Otherwise a redundant check and a lookup will be necessary: Object[char[]] map; if (auto o = "test" in map) { // this is redundant, in my opinion delete map.remove("test"); } and it is exactly the same as: if (auto o = "test" in map) { map.remove("test"); delete *o; }
Jul 19 2008
"Koroskin Denis" <2korden+dmd gmail.com> wrote in message news:op.uejmwq0sn8fdl4 korden...On Sat, 19 Jul 2008 16:39:18 +0400, Stewart Gordon <smjg_1998 yahoo.com> wrote:Are you missing my point, or guessing what Max meant?But .remove has to return something. So how is this possible?It doesn't return anything now.What if the value type has no null?And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception?I think returning null is ok. Otherwise a redundant check and a lookup will be necessary:Object[char[]] map; if (auto o = "test" in map) { // this is redundant, in my opinion delete map.remove("test"); }<snip> Indeed, the "auto o =" bit is unnecessary here. Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Jul 19 2008
On Sat, 19 Jul 2008 19:25:15 +0400, Stewart Gordon <smjg_1998 yahoo.com> wrote:"Koroskin Denis" <2korden+dmd gmail.com> wrote in message news:op.uejmwq0sn8fdl4 korden...Hmm.. I missed that. At first, I though than remove() behaviour should be consistent with opIn(), i.e. it should return a pointer to a value, but it is not possible. Looks like the best guess is to return the stored value or T.init, if no value is found (i.e. null for ref types and some default value for value types).I think returning null is ok. Otherwise a redundant check and a lookup will be necessary:What if the value type has no null?
Jul 19 2008
Stewart Gordon wrote:"Koroskin Denis" <2korden+dmd gmail.com> wrote in message news:op.uejmwq0sn8fdl4 korden...I think the compiler should remove the extra delete so that writing generic code is easy. Alternatively the compiler could report an error if delete doesn't work with the given type however I less like that option. Also you could do this if remove returned something: auto value = map.remove("test"); assert(value); //Value not found. delete value;On Sat, 19 Jul 2008 16:39:18 +0400, Stewart Gordon <smjg_1998 yahoo.com> wrote:Are you missing my point, or guessing what Max meant?But .remove has to return something. So how is this possible?It doesn't return anything now.What if the value type has no null?And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception?I think returning null is ok. Otherwise a redundant check and a lookup will be necessary:IObject[char[]] map; if (auto o = "test" in map) { // this is redundant, in my opinion delete map.remove("test"); }<snip> Indeed, the "auto o =" bit is unnecessary here. Stewart.
Jul 19 2008
Stewart Gordon, el 19 de julio a las 13:39 me escribiste:"Max Samukha" <samukha voliacable.com.removethis> wrote in message news:d85384p9e1heua1f8f6vn2cesd9cosjlrc 4ax.com...If the idea was to add an assert in the remove code, I guess he meant not to raise an assert exception if compiled with the release flag. In case the exception is not raised that could just be undefined behavior (SIGSEGV or whatever).On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon" <smjg_1998 yahoo.com> wrote:And do what if the program wasn't built with a "debug switch"? Moreover, I personally think that debug switches should be saved for programmer-defined debug code."Max Samukha" <samukha voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m 4ax.com... <snip>Three options: 1. Throw an assert exception if the program was built with a debug switchIf 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x");<snip> And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception? Stewart.I think this solution can be perfectly viable too. But I still think delete hash["x"]; should just work =) -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- Software is like sex: it's better when it's free. -- Linus Torvalds2. Always throw an exception 3. Make 'remove' return a pointer to the valueAnd so if the key isn't present, return null. Hmm.... I guess it would be the programmer's responsibility not to keep lots of these pointers alive and thereby prevent the AA nodes from being GC'd. Hmm....
Jul 19 2008
On Sat, 19 Jul 2008 13:39:18 +0100, "Stewart Gordon" <smjg_1998 yahoo.com> wrote:"Max Samukha" <samukha voliacable.com.removethis> wrote in message news:d85384p9e1heua1f8f6vn2cesd9cosjlrc 4ax.com...I agree, "debug switch" is BS. What I meant is non-release builds. Trying to remove non-existent elements would result in undefined behavior in release builds.On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon" <smjg_1998 yahoo.com> wrote:And do what if the program wasn't built with a "debug switch"?"Max Samukha" <samukha voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m 4ax.com... <snip>Three options: 1. Throw an assert exception if the program was built with a debug switchIf 'remove' was modified to return the removed value, more compact syntax would be possible: delete hash.remove("x");<snip> And what would remove do if the key is already not in the AA? Return ValueType.init? Throw an exception? Stewart.Moreover, I personally think that debug switches should be saved for programmer-defined debug code.It has been proposed that array bounds checking should be controlled by a separate switch.I don't think that is an issue. Why would there be "lots of these pointers"? Most of the time the return values of 'remove' wouldn't be used at all. Anyway, as pointers are nowadays in dishonor, this option is not going to be accepted.2. Always throw an exception 3. Make 'remove' return a pointer to the valueAnd so if the key isn't present, return null. Hmm.... I guess it would be the programmer's responsibility not to keep lots of these pointers alive and thereby prevent the AA nodes from being GC'd. Hmm....You are right. This is not an option.4. Continue silentlyBut .remove has to return something. So how is this possible?I prefer the first option. Option 4 (current semantics) is the least acceptible, in my opinion.Hang on ... is 4 meant to be an option under the premise that we want .remove to return the removed value, or the option of not implementing this feature at all?
Jul 19 2008
On Tue, 15 Jul 2008 13:40:07 -0300, Leandro Lucarella wrote:Max Samukha, el 15 de julio a las 17:54 me escribiste:FWIW: I'm used to include this little helper in my code: V get(V, K)(V[K] aa, K key) { auto ptr = (key in aa); return ptr ? (*ptr) : null; } It boils down to: delete aa.get("x"); I would appreciate if an associative array would return the plain value, from a practical point. The problem comes if you want to store 0, or null as key by purpose. But I think it is programmers task in these rare circumstances to insert a wrapped pointer. -my2centsIt just gets better and better ;)An alternative hack: delete *("x" in hash);Phew! That's much better! (!) o_ONo I don't. delete * cast(Object*) &hash["x"];If not, do I have to do: auto c = hash["x"]; hash.remove["x"]; delete c;Yeah, you do.
Jul 16 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.
Feb 11 2008
BCS, el 11 de febrero a las 20:23 me escribiste:Reply to Leandro,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 ConstanzaI 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.
Feb 11 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.
Feb 11 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.
Feb 11 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.
Jul 14 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>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.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....
Jul 14 2008
Simen Kjaeraas wrote:I'm always interested in using more compact and more general versions of functions, rather than having to take more steps, so Fourthed!JAnderson wrote:"Koroskin Denis"Max Samukha wrote:On Wed, 16 Jul 2008 01:23:30 +0400,pointer from a collection:<2korden+dmd gmail.com> wrote:But you still have to remove a deadremoved value, more compactdelete *("x" in hash); hash.remove("x");If 'remove' was modified to return thevalue twice andsyntax would be possible: delete hash.remove("x"); Also, there would be no need to search for theis needed for furtherintroduce a temporary when the removed valuepass it to a functionprocessing: // do something with the value, for example,Thirded!Seconded! Regan Heathfoo(hash.remove("x")); instead of: auto v = hash["x"]; hash.remove("x"); foo(v);I think this is a good idea.
Jul 19 2008