digitalmars.D.learn - Clearing associative array.
- ciechowoj (18/18) Mar 12 2016 Could someone explain to me, why following code does not compile?
- Adam D. Ruppe (8/10) Mar 12 2016 Read the Tip of the Week section here:
- ciechowoj (4/14) Mar 12 2016 Nice article :), thanks. But still, what about clear()? In the
- Adam D. Ruppe (3/6) Mar 12 2016 I don't think that actually works... might be out of date
- Steven Schveighoffer (7/13) Mar 15 2016 Opposite. The next version of dmd will have a clear property.
- cym13 (4/22) Mar 13 2016 The problem was brought up a few days ago (can't remember where)
- ciechowoj (2/5) Mar 13 2016 That would be great : )
Could someone explain to me, why following code does not compile? int main() { string[string] x = [ "foo" : "bar" ]; x.clear(); x = []; return 0; } Errors: main.d(7): Error: no property 'clear' for type 'string[string]' main.d(8): Error: cannot implicitly convert expression ([]) of type void[] to string[string] Failed: ["dmd", "-v", "-o-", "main.d", "-I."] If above doesn't work how am I supposed to clear the array? `x = string[string].init;` is somewhat ugly. dmd --version DMD64 D Compiler v2.070.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
Mar 12 2016
On Saturday, 12 March 2016 at 12:34:16 UTC, ciechowoj wrote:If above doesn't work how am I supposed to clear the array? `x = string[string].init;` is somewhat ugly.Read the Tip of the Week section here: http://arsdnet.net/this-week-in-d/dec-13.html Short answer: use `= null` to clear the AA. [] doesn't work just because the compiler is a bit stupid about the type you intend it to be, but null works fine. BTW you might want to glance through more of the issues for the tip section too and see if there's more that interest you.
Mar 12 2016
On Saturday, 12 March 2016 at 12:42:04 UTC, Adam D. Ruppe wrote:On Saturday, 12 March 2016 at 12:34:16 UTC, ciechowoj wrote:Nice article :), thanks. But still, what about clear()? In the documentation https://dlang.org/spec/hash-map.html#properties there is written that associative arrays have clear property.If above doesn't work how am I supposed to clear the array? `x = string[string].init;` is somewhat ugly.Read the Tip of the Week section here: http://arsdnet.net/this-week-in-d/dec-13.html Short answer: use `= null` to clear the AA. [] doesn't work just because the compiler is a bit stupid about the type you intend it to be, but null works fine. BTW you might want to glance through more of the issues for the tip section too and see if there's more that interest you.
Mar 12 2016
On Saturday, 12 March 2016 at 12:59:02 UTC, ciechowoj wrote:Nice article :), thanks. But still, what about clear()? In the documentation https://dlang.org/spec/hash-map.html#properties there is written that associative arrays have clear property.I don't think that actually works... might be out of date documentation, I'm not sure.
Mar 12 2016
On 3/12/16 8:09 AM, Adam D. Ruppe wrote:On Saturday, 12 March 2016 at 12:59:02 UTC, ciechowoj wrote:Opposite. The next version of dmd will have a clear property. Apparently, we don't have a good system to merge doc changes in concert with future master releases. Whatever gets pulled apparently gets built as the current docs. See PR: https://github.com/D-Programming-Language/dlang.org/pull/1217 -SteveNice article :), thanks. But still, what about clear()? In the documentation https://dlang.org/spec/hash-map.html#properties there is written that associative arrays have clear property.I don't think that actually works... might be out of date documentation, I'm not sure.
Mar 15 2016
On Saturday, 12 March 2016 at 12:59:02 UTC, ciechowoj wrote:On Saturday, 12 March 2016 at 12:42:04 UTC, Adam D. Ruppe wrote:The problem was brought up a few days ago (can't remember where) and it happens to be a documentation mistake: there is a clear() method planned but for a future release (the next one?).On Saturday, 12 March 2016 at 12:34:16 UTC, ciechowoj wrote:Nice article :), thanks. But still, what about clear()? In the documentation https://dlang.org/spec/hash-map.html#properties there is written that associative arrays have clear property.If above doesn't work how am I supposed to clear the array? `x = string[string].init;` is somewhat ugly.Read the Tip of the Week section here: http://arsdnet.net/this-week-in-d/dec-13.html Short answer: use `= null` to clear the AA. [] doesn't work just because the compiler is a bit stupid about the type you intend it to be, but null works fine. BTW you might want to glance through more of the issues for the tip section too and see if there's more that interest you.
Mar 13 2016
On Sunday, 13 March 2016 at 13:42:02 UTC, cym13 wrote:The problem was brought up a few days ago (can't remember where) and it happens to be a documentation mistake: there is a clear() method planned but for a future release (the next one?).That would be great : )
Mar 13 2016