Associative arrays

2015-11-08 Thread TheFlyingFiddle via Digitalmars-d-learn
I have a few questions about the pseudo built in associative arrays. 1. Is it possible to have the built in associative array use a custom allocator from std.experimental.allocator to service it's allocation needs? 2. A while ago I read on the newsgroup a while back that there was a

associative arrays

2012-01-07 Thread RenatoL
Very quick question import std.stdio; void main() { auto arr1 = ["uno":1, "due":2, "tre":3]; arr1.remove("xxx"); } also in this case the compiler does not say anything and the program goes out silently ... why? Would not it be better if an exception was raised? After all if i writ

Re: Associative arrays

2015-11-08 Thread Rikki Cattermole via Digitalmars-d-learn
On 09/11/15 4:57 PM, TheFlyingFiddle wrote: I have a few questions about the pseudo built in associative arrays. 1. Is it possible to have the built in associative array use a custom allocator from std.experimental.allocator to service it's allocation needs? Nope. 2. A while ago I re

Re: Associative arrays

2015-11-08 Thread rsw0x via Digitalmars-d-learn
On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: On 09/11/15 4:57 PM, TheFlyingFiddle wrote: [...] Nope. [...] As far as I'm aware, you are stuck using e.g. structs to emulate AA behavior. I have a VERY basic implementation here: https://github.com/rikkimax/alphaPhobos

Re: Associative arrays

2015-11-09 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: On 09/11/15 4:57 PM, TheFlyingFiddle wrote: [...] Nope. [...] As far as I'm aware, you are stuck using e.g. structs to emulate AA behavior. I have a VERY basic imp

Re: Associative arrays

2015-11-09 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: Fwiw, EMSI provides high quality containers backed by std.experimental.allocator. https://github.com/economicmodeling/containers I have a question regarding the impleme

Re: Associative arrays

2015-11-09 Thread rsw0x via Digitalmars-d-learn
On Monday, 9 November 2015 at 21:33:09 UTC, TheFlyingFiddle wrote: On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: Fwiw, EMSI provides high quality containers backed by std.experimental.allocator. https://github.com/e

Re: Associative arrays

2015-11-09 Thread Brian Schott via Digitalmars-d-learn
On Monday, 9 November 2015 at 21:33:09 UTC, TheFlyingFiddle wrote: On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: Fwiw, EMSI provides high quality containers backed by std.experimental.allocator. https://github.com/e

Re: Associative arrays

2015-11-09 Thread Brian Schott via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 01:29:11 UTC, Brian Schott wrote: Yes. It's a hack that gives you a modulus without having to do a modulus. It only works on powers of two. http://graphics.stanford.edu/~seander/bithacks.html#ModulusDivisionEasy

Re: associative arrays

2012-01-07 Thread Ali Çehreli
On 01/07/2012 02:11 PM, RenatoL wrote: > Very quick question > > import std.stdio; > void main() > { >auto arr1 = ["uno":1, "due":2, "tre":3]; >arr1.remove("xxx"); > } > > also in this case the compiler does not say anything and the > program goes out silently ... why? Would not it be bett

Re: associative arrays

2012-01-07 Thread Manfred Nowak
RenatoL wrote: > Would not it be better if an exception was raised? No, because exceptions are guarenteed to be slow. > if i write: writeln(arr1["xxx"]); > runtime expresses its disappointment... I would be disappointed too, if the commands for removing and for requesting something are sequence

Re: associative arrays

2012-01-07 Thread RenatoL
Yes, i agree this may acceptable. On the other hand if i really want/have to remove an item i have to be very careful cause a trivial typo could cause a disaster

Re: associative arrays

2012-01-07 Thread Jonathan M Davis
On Saturday, January 07, 2012 15:06:30 Ali Çehreli wrote: > On 01/07/2012 02:11 PM, RenatoL wrote: > > Very quick question > > > > import std.stdio; > > void main() > > { > > > >auto arr1 = ["uno":1, "due":2, "tre":3]; > >arr1.remove("xxx"); > > > > } > > > > also in this ca

Re: associative arrays

2012-01-07 Thread Jonathan M Davis
On Saturday, January 07, 2012 23:34:05 RenatoL wrote: > Yes, i agree this may acceptable. On the other hand if i really > want/have to remove an item i have to be very careful cause a > trivial typo could cause a disaster In general, if an element isn't in a container, and you expect it to be

Re: associative arrays

2012-01-07 Thread Manfred Nowak
Jonathan M Davis wrote: [...] This sort of explanation is missing in the docs. -manfred

Re: associative arrays

2012-01-07 Thread Jonathan M Davis
On Sunday, January 08, 2012 00:13:12 Manfred Nowak wrote: > Jonathan M Davis wrote: > > [...] > > This sort of explanation is missing in the docs. Which part? - Jonathan M Davis

Re: associative arrays

2012-01-07 Thread RenatoL
Yes, Jonathan, you're right. the question arose precisely from a typo... i had to remove an item with key "length"... i wrote "lengt" and the item never went away... i knew that "lengt" was not in my key list... This kind of mistake is quite tricky, may be using and IDE could help.

Re: associative arrays

2012-01-07 Thread bearophile
istake is quite tricky, may be using and IDE could help. This an example that shows that silent failures are sources of bugs... So this time I don't agree with Jonathan Davis. Python Zen contains: Errors should never pass silently. And Python associative arrays show it: >>> d = {

Re: associative arrays

2012-01-07 Thread Jonathan M Davis
On Saturday, January 07, 2012 21:54:07 bearophile wrote: > Maybe D associative arrays too should have both kinds of deleting methods > :-) Why? What's the gain? If you care that the element is already in the AA, then do either assert(key in aa); aa.remove(key); or enforc

Re: associative arrays

2012-01-07 Thread Manfred Nowak
Jonathan M Davis wrote: > So, as far as I can tell, the current situation is more efficient There are some more arguments: 1) Different threads might want to `remove' the same key from the AA. I don't see a reason why only the first served thread should complete the operation without an error.

Re: associative arrays

2012-01-07 Thread Kapps
For most languages (such as C# and maybe Java), the Remove method on collections returns a boolean indicating whether it was removed. So you could write: enforce(MyAA.remove("lenght")) or bool Result = MyAA.remove("lenght"); assert(Result); I'm not sure why it doesn't in D, but I thought I rem

Re: associative arrays

2012-01-08 Thread Stephen Bennett
On 1/7/2012 8:54 PM, bearophile wrote: >> Yes, Jonathan, you're right. >> the question arose precisely from a typo... i had to remove an >> item with key "length"... i wrote "lengt" and the item never went >> away... i knew that "lengt" was not in my key list... This kind of >> mistake is quite tri

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 01:39:24 Kapps wrote: > For most languages (such as C# and maybe Java), the Remove method on > collections returns a boolean indicating whether it was removed. So you > could write: > > enforce(MyAA.remove("lenght")) > or > bool Result = MyAA.remove("lenght"); > assert(

Re: associative arrays

2012-01-08 Thread Kapps
Ah, found the bug / pull request. https://github.com/D-Programming-Language/dmd/pull/597 http://d.puremagic.com/issues/show_bug.cgi?id=4523 On 08/01/2012 1:39 AM, Kapps wrote: For most languages (such as C# and maybe Java), the Remove method on collections returns a boolean indicating whether i

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 03:24:22 Kapps wrote: > Ah, found the bug / pull request. > > https://github.com/D-Programming-Language/dmd/pull/597 > http://d.puremagic.com/issues/show_bug.cgi?id=4523 Ah, TDPL says that it returns bool. Well, then it definitely needs to be changed, and it's good to

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 10:43, Jonathan M Davis wrote: On Sunday, January 08, 2012 03:24:22 Kapps wrote: Ah, found the bug / pull request. https://github.com/D-Programming-Language/dmd/pull/597 http://d.puremagic.com/issues/show_bug.cgi?id=4523 Ah, TDPL says that it returns bool. Well, then it definite

Re: associative arrays

2012-01-08 Thread Manfred Nowak
simendsjo wrote: > Wouldn't it make sense to return a pointer to the item being > removed/null? According to the docs this is the intended behavior. -manfred

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 11:09, Manfred Nowak wrote: simendsjo wrote: Wouldn't it make sense to return a pointer to the item being removed/null? According to the docs this is the intended behavior. -manfred The only mention I can see of remove is at the top, and it doesn't state return value: http:/

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 11:02:41 simendsjo wrote: > On 08.01.2012 10:43, Jonathan M Davis wrote: > > On Sunday, January 08, 2012 03:24:22 Kapps wrote: > >> Ah, found the bug / pull request. > >> > >> https://github.com/D-Programming-Language/dmd/pull/597 > >> http://d.puremagic.com/issues/show

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 11:27, Jonathan M Davis wrote: On Sunday, January 08, 2012 11:02:41 simendsjo wrote: On 08.01.2012 10:43, Jonathan M Davis wrote: On Sunday, January 08, 2012 03:24:22 Kapps wrote: Ah, found the bug / pull request. https://github.com/D-Programming-Language/dmd/pull/597 http://d.p

Re: associative arrays

2012-01-08 Thread Andrej Mitrovic
On 1/8/12, simendsjo wrote: > Wouldn't it make sense to return a pointer to the item being > removed/null? Seems like that would be even more costly. Personally I think returning bool is unnecessary, if we really want to know if something is in the hash we can check with the `in` operator. I fil

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 11:33:51 simendsjo wrote: > I was thinking it could be a shorthand for the following: > > auto item = key in aa; > if (item) key.remove(key); I take it that you then intend to use item after that? I'm not sure that item is actually valid at that point. It points to me

Re: associative arrays

2012-01-08 Thread Manfred Nowak
simendsjo wrote: > it doesn't state return value Yes, I haven't read carefully enough. -manfred

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 12:18, Jonathan M Davis wrote: On Sunday, January 08, 2012 11:33:51 simendsjo wrote: I was thinking it could be a shorthand for the following: auto item = key in aa; if (item) key.remove(key); I take it that you then intend to use item after that? I'm not sure that item is actua

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 12:35:27 simendsjo wrote: > On 08.01.2012 12:18, Jonathan M Davis wrote: > > On Sunday, January 08, 2012 11:33:51 simendsjo wrote: > >> I was thinking it could be a shorthand for the following: > >> > >> auto item = key in aa; > >> if (item) key.remove(key); > > > > I

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 12:57, Jonathan M Davis wrote: On Sunday, January 08, 2012 12:35:27 simendsjo wrote: On 08.01.2012 12:18, Jonathan M Davis wrote: On Sunday, January 08, 2012 11:33:51 simendsjo wrote: I was thinking it could be a shorthand for the following: auto item = key in aa; if (item) key.

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 13:06:06 simendsjo wrote: > Certainly not obvious to me :) Well, what's obvious to one person is not always obvious to another. I'm sure that there are plenty of things that Walter thinks should be perfectly obvious which 90% of programmers would never think of. A lot

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 13:49, Jonathan M Davis wrote: On Sunday, January 08, 2012 13:06:06 simendsjo wrote: Certainly not obvious to me :) Well, what's obvious to one person is not always obvious to another. I'm sure that there are plenty of things that Walter thinks should be perfectly obvious which 9

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 14:24:32 simendsjo wrote: > Thanks for your clarifications. > > Does this mean even this is undefined? > aa["a"] = new C(); > auto c = "a" in aa; > aa["b"] = new C(); > // Using c here is undefined as an element was added to aa Yes. Depending on the current implementat

Re: associative arrays

2012-01-08 Thread Manfred Nowak
Jonathan M Davis wrote: > In this case, it's very much like dealing with C++ iterators A relevant part of Andrei's thread on "associative arrays iteration": http://www.digitalmars.com/d/archives/digitalmars/D/associative_arrays_ iteration_is_finally_here_99576.html#N99614 -manfred

Re: associative arrays

2012-01-08 Thread simendsjo
On 08.01.2012 14:40, Jonathan M Davis wrote: On Sunday, January 08, 2012 14:24:32 simendsjo wrote: Thanks for your clarifications. Does this mean even this is undefined? aa["a"] = new C(); auto c = "a" in aa; aa["b"] = new C(); // Using c here is undefined as an element was added to aa Yes. D

Re: associative arrays

2012-01-08 Thread Jonathan M Davis
On Sunday, January 08, 2012 14:57:51 simendsjo wrote: > On 08.01.2012 14:40, Jonathan M Davis wrote: > > On Sunday, January 08, 2012 14:24:32 simendsjo wrote: > >> Thanks for your clarifications. > >> > >> Does this mean even this is undefined? > >> aa["a"] = new C(); > >> auto c = "a" in aa; > >>

Re: associative arrays

2012-01-08 Thread Jesse Phillips
Based on these arguments does that mean std.file.remove should not be throwing when a file doesn't exist? Or more precisely should I add a bugzilla entry to change this. I certainly have a lot of if(exists) remove() in my code and end up having to change where I just use remove(). On Sunday,

Re: associative arrays

2012-01-08 Thread RenatoL
Very interesting discussion. Tk u all.

Re: associative arrays

2012-01-09 Thread Kapps
Looks like this is fixed for 2.058. https://github.com/D-Programming-Language/dmd/commit/3e23b0f5834acb32eaee20d88c30ead7e03bb2f4 On 08/01/2012 3:43 AM, Jonathan M Davis wrote: On Sunday, January 08, 2012 03:24:22 Kapps wrote: Ah, found the bug / pull request. https://github.com/D-Programming

Re: associative arrays

2012-01-09 Thread dennis luehring
assert(key in aa); aa.remove(key); So, as far as I can tell, the current situation is more efficient, and it doesn't cost you any expressiveness. You can still have an exception thrown when remove fails if you use enforce before the call if you want an exception thrown when the element isn't ther

Re: associative arrays

2012-01-09 Thread Steven Schveighoffer
On Sun, 08 Jan 2012 08:40:27 -0500, Jonathan M Davis wrote: On Sunday, January 08, 2012 14:24:32 simendsjo wrote: Thanks for your clarifications. Does this mean even this is undefined? aa["a"] = new C(); auto c = "a" in aa; aa["b"] = new C(); // Using c here is undefined as an element was a

Re: associative arrays

2012-01-09 Thread Jonathan M Davis
On Monday, January 09, 2012 09:25:14 Steven Schveighoffer wrote: > Actually, not invalid for the current implementation. I don't know if > it's stated whether an AA specifically requires that elements do not > re-associate on a rehash. Well, like I said, it depends on the current implementation. T

Re: associative arrays

2012-01-09 Thread Andrej Mitrovic
On 1/9/12, Steven Schveighoffer wrote: > BTW, dcollections' HashMap, HashSet, and HashMultiset do guarantee that > adding elements does not invalidated cursors (dcollections' safe version > of pointers) as long as you use the default Hash implementation. However, > I just noticed this is not stat

Re: associative arrays

2012-01-09 Thread Steven Schveighoffer
On Mon, 09 Jan 2012 13:35:26 -0500, Andrej Mitrovic wrote: On 1/9/12, Steven Schveighoffer wrote: BTW, dcollections' HashMap, HashSet, and HashMultiset do guarantee that adding elements does not invalidated cursors (dcollections' safe version of pointers) as long as you use the default Hash

Re: associative arrays

2012-01-09 Thread Andrej Mitrovic
Ok, allow me to temporarily hijack again and ask: Would you mind adding opIn_r (or rather the newer opBinaryRight with "in") that forwards to contains() for the HashSet and similar hash-based classes that define contains()? It would make porting code that uses builtin hashes to your own implementat

Re: associative arrays

2012-01-09 Thread Steven Schveighoffer
On Mon, 09 Jan 2012 14:57:36 -0500, Andrej Mitrovic wrote: Ok, allow me to temporarily hijack again and ask: Would you mind adding opIn_r (or rather the newer opBinaryRight with "in") that forwards to contains() for the HashSet and similar hash-based classes that define contains()? It would m

Re: associative arrays

2012-01-09 Thread Andrej Mitrovic
On 1/9/12, Steven Schveighoffer wrote: > Could this be you? Ah, yes. I didn't even notice you've replied to that, sorry. Yes, I'm ok with it.

Re: associative arrays

2012-01-09 Thread Manfred Nowak
dennis luehring wrote: > why is there an exception/error neeeded if missing? Exceptions or errors are not _needed_. Their existence stems from the modell under which the user of the operation _has_ to think about the operation, especially whether it is a:only the outcome of the operation or

Re: associative arrays

2012-01-09 Thread dennis luehring
Am 09.01.2012 22:08, schrieb Manfred Nowak: dennis luehring wrote: why is there an exception/error neeeded if missing? Exceptions or errors are not _needed_. Their existence stems from the modell under which the user of the operation _has_ to think about the operation, especially whether it

Re: associative arrays

2012-01-10 Thread Manfred Nowak
dennis luehring wrote: > so your FileDelete would not return an FileDoesNotExists-Error? Correct. > would it not help to better understand big code if the remove > would be renamed to remove_existing or to add something like this? Maybe. You possibly know about the `rm'-command of *nix-like sys

Static Associative Arrays

2012-04-07 Thread Caligo
I'm not questioning the design, but I would like to know the reason: given the fact that associative arrays are built into the language, why don't we have static associative arrays?

Variant associative arrays

2013-05-08 Thread Byron Heads
I have a variant associative array. In the example below I am wondering if there is a way to create the array without having to indicate the variant type on all of the values. Would like to be able to write code like #2, or something cleaner/better for #1. This is intended for a library. Othe

Nested associative arrays

2010-11-12 Thread Jacob Carlborg
Is D supposed to be able to handle nested associative arrays ? -- /Jacob Carlborg

Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { writeln(val); } I solved i

trouble with associative Arrays

2024-01-20 Thread atzensepp via Digitalmars-d-learn
Hello, I am new with D and want to convert a c program for a csv file manipulation with exhaustive dynamic memory mechanics to D . When reading a CSV-file line by line I would like to create an associative array to get the row values by the value in the second column. Although I save the row

Merging two associative arrays

2019-08-24 Thread berni via Digitalmars-d-learn
I've got two associative arrays and want to get a new one, which is created out of both of them: This works: string[int] a = [1:"one", 7:"seven"]; string[int] b = [5:"five", 9:"nine"]; string[int] tmp = a.dup; foreach (k,v;b) tmp[k] = v; asser

Re: Static Associative Arrays

2012-04-07 Thread Jonathan M Davis
On Saturday, April 07, 2012 18:45:40 Caligo wrote: > I'm not questioning the design, but I would like to know the reason: > given the fact that associative arrays are built into the language, > why don't we have static associative arrays? What do you mean my static associat

Re: Static Associative Arrays

2012-04-07 Thread H. S. Teoh
On Sat, Apr 07, 2012 at 09:01:40PM -0700, Jonathan M Davis wrote: > On Saturday, April 07, 2012 18:45:40 Caligo wrote: > > I'm not questioning the design, but I would like to know the reason: > > given the fact that associative arrays are built into the language, > >

Re: Static Associative Arrays

2012-04-07 Thread Caligo
On Sat, Apr 7, 2012 at 11:01 PM, Jonathan M Davis wrote: > > What do you mean my static associative arrays? Are you asking why you can't > initialize a static variable which is an AA at compile time? e.g. > > - Jonathan M Davis The same way I can create a static array:

Re: Static Associative Arrays

2012-04-07 Thread Jonathan M Davis
On Sunday, April 08, 2012 01:24:02 Caligo wrote: > On Sat, Apr 7, 2012 at 11:01 PM, Jonathan M Davis wrote: > > What do you mean my static associative arrays? Are you asking why you > > can't > > initialize a static variable which is an AA at compile time? e.g. &

Re: Static Associative Arrays

2012-04-12 Thread Christophe
Jonathan M Davis , dans le message (digitalmars.D.learn:34332), a écrit : > On Sunday, April 08, 2012 01:24:02 Caligo wrote: >> On Sat, Apr 7, 2012 at 11:01 PM, Jonathan M Davis > wrote: >> > What do you mean my static associative arrays? Are you asking why you >>

Re: Variant associative arrays

2013-05-08 Thread bearophile
Byron Heads: I have a variant associative array. In the example below I am wondering if there is a way to create the array without having to indicate the variant type on all of the values. Would like to be able to write code like #2, or something cleaner/better for #1. ... // #1 This

Re: Variant associative arrays

2013-05-08 Thread evilrat
On Thursday, 9 May 2013 at 00:10:48 UTC, Byron Heads wrote: I have a variant associative array. In the example below I am wondering if there is a way to create the array without having to indicate the variant type on all of the values. Would like to be able to write code like #2, or something

Re: Variant associative arrays

2013-05-09 Thread Byron Heads
On Thu, 09 May 2013 03:29:06 +0200, evilrat wrote: > first doesn't compile with DMD 2.062 as int implicitly not converted to > long. > > foo func takes associative array, within this example you can use type > Variant[string] to make life a bit easier(but i can't recommend it for > ur real code c

Re: Variant associative arrays

2013-05-09 Thread Byron Heads
On Thu, 09 May 2013 02:33:08 +0200, bearophile wrote: > Byron Heads: > >> I have a variant associative array. In the example below I am >> wondering if there is a way to create the array without having to >> indicate the variant type on all of the values. Would like to be able >> to write code l

Re: Nested associative arrays

2010-11-12 Thread Ellery Newcomer
Should be. Are you having problems? (I don't use them much, but fwiw, it seems like tango had some [trivial?] problems with them) On 11/12/2010 10:08 AM, Jacob Carlborg wrote: Is D supposed to be able to handle nested associative arrays ?

Re: Nested associative arrays

2010-11-13 Thread Jacob Carlborg
On 2010-11-12 17:44, Ellery Newcomer wrote: Should be. Are you having problems? (I don't use them much, but fwiw, it seems like tango had some [trivial?] problems with them) On 11/12/2010 10:08 AM, Jacob Carlborg wrote: Is D supposed to be able to handle nested associative arrays ?

Re: Nested associative arrays

2010-11-13 Thread bearophile
Jacob Carlborg: > module main; > > void main () > { > auto tree = ["" : ["" : ""]]; > } > > Using DMD 1.065 results in: > > Assertion failed: (0), function toExpression, file init.c, line 437. Please put it in Bugzilla if not already present :-) Bye, bearophile

Re: Nested associative arrays

2010-11-13 Thread div0
le to handle nested associative arrays ? Well, yes. The following code: module main; void main () { auto tree = ["" : ["" : ""]]; } Using DMD 1.065 results in: Assertion failed: (0), function toExpression, file init.c, line 437. That's static initialisati

Re: Nested associative arrays

2010-11-13 Thread Jacob Carlborg
lborg wrote: Is D supposed to be able to handle nested associative arrays ? Well, yes. The following code: module main; void main () { auto tree = ["" : ["" : ""]]; } Using DMD 1.065 results in: Assertion failed: (0), function toExpression, file init.c, line 437.

Re: Nested associative arrays

2010-11-13 Thread Jacob Carlborg
On 2010-11-13 14:39, bearophile wrote: Jacob Carlborg: module main; void main () { auto tree = ["" : ["" : ""]]; } Using DMD 1.065 results in: Assertion failed: (0), function toExpression, file init.c, line 437. Please put it in Bugzilla if not already present :-) Bye, bearophile

Re: Nested associative arrays

2010-11-13 Thread Ellery Newcomer
Wow. Yeah, I guess all bets are off when it comes to initializations. In the meantime, I guess you'll have to use string[string][string] tree; tree = ["" : ["" : ""]]; On 11/13/2010 05:02 AM, Jacob Carlborg wrote: Well, yes. The following code: module main; void main () { auto tree = ["" :

Re: Nested associative arrays

2010-11-13 Thread div0
them) On 11/12/2010 10:08 AM, Jacob Carlborg wrote: Is D supposed to be able to handle nested associative arrays ? Well, yes. The following code: module main; void main () { auto tree = ["" : ["" : ""]]; } Using DMD 1.065 results in: Assertion failed: (0),

Re: Nested associative arrays

2010-11-13 Thread spir
On Sat, 13 Nov 2010 17:27:08 + div0 wrote: > > How about "associative array literal" then? Regardless of what you call > > it I shouldn't get an assertion failure. > > > > True. It's been fixed in dmd2 though, you get: > > Error: Integer constant expression expected instead of "" > > Whe

Re: Nested associative arrays

2010-11-13 Thread div0
On 13/11/2010 20:02, spir wrote: On Sat, 13 Nov 2010 17:27:08 + div0 wrote: How about "associative array literal" then? Regardless of what you call it I shouldn't get an assertion failure. True. It's been fixed in dmd2 though, you get: Error: Integer constant expression expected instea

Re: Nested associative arrays

2010-11-13 Thread bearophile
div0: > I finally found the bit where it describes associative array literals > and they look identical to initialising a flat array, so god only knows > which one gets picked when. It would be better if they where made different. One of my many enhancement requests, no one disturbs their sleep

Re: Nested associative arrays

2010-11-13 Thread Ellery Newcomer
On 11/13/2010 02:02 PM, spir wrote: On Sat, 13 Nov 2010 17:27:08 + But the compiler (D2) accepts nested aa literals remaining anonymous: writeln(["a" : ["b" : "c"]]);// --> "a:b:c" (where "auto aa = ..." fails) The difference is initializer vs expression. initializers occu

Re: Nested associative arrays

2010-11-13 Thread div0
On 14/11/2010 00:28, Ellery Newcomer wrote: On 11/13/2010 02:02 PM, spir wrote: On Sat, 13 Nov 2010 17:27:08 + But the compiler (D2) accepts nested aa literals remaining anonymous: writeln(["a" : ["b" : "c"]]); // --> "a:b:c" (where "auto aa = ..." fails) The difference is initializer

Re: Nested associative arrays

2010-11-14 Thread spir
On Sun, 14 Nov 2010 00:03:48 + div0 wrote: > yeah, but dmd's parser was written by hand so it's not surprising there > are inconsistency's with what works where. Well, most (all?) truely used languages have hand-written parsers, AFAIK. The issue is not with writing the parser, I guess, bu

Re: Nested associative arrays

2010-11-14 Thread spir
On Sun, 14 Nov 2010 10:35:42 +0100 spir wrote: > > I finally found the bit where it describes associative array literals > > and they look identical to initialising a flat array, so god only knows > > which one gets picked when. It would be better if they where made > > different. > > ... w

Re: Nested associative arrays

2010-11-14 Thread Jacob Carlborg
o had some [trivial?] problems with them) On 11/12/2010 10:08 AM, Jacob Carlborg wrote: Is D supposed to be able to handle nested associative arrays ? Well, yes. The following code: module main; void main () { auto tree = ["" : ["" : ""]]; } Using DMD 1.06

Associative arrays not ?:'d

2010-12-11 Thread Robert Clipsham
I was under the impression that associative arrays now used ?: to find the best type for the array? Or was this change only made in D2? The following: void main() { auto foo = [ 2 : "a", 3 : "ab" ]; } Gives the error: test.d(3): Error: cannot implicitl

Problem with associative arrays

2011-03-19 Thread Piotr Szturmaj
Shouldn't dynamic array be reference type? uint[][uint] aa; uint[] temp; aa[5] = new uint[0]; temp = aa[5]; // copy uint[] reference temp ~= 1; assert(temp.length == 1 && temp[0] == 1); // pass assert(aa[5].length == 1 && aa[5][0] == 1); // fail Is this a bug?

Associative arrays, multithreading, Rebindable

2014-04-12 Thread Jack Applegame
Foo) foo; foo = new immutable Foo; // fine But for immutable associative arrays we can't: Rebindable!(immutable int[string]) foo; // error foo = assumeUnique(other); Error: template instance std.typecons.Rebindable!(immutable(int[string])) does not match template declaration Rebindable(T) i

Reserving capacity in associative arrays

2016-02-14 Thread Jon D via Digitalmars-d-learn
Is there a way to reserve capacity in associative arrays? In some programs I've been writing I've been getting reasonable performance up to about 10 million entries, but beyond that performance is impacted considerably (say, 30 million or 50 million entries). GC stats (via the &q

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "

Re: Top level associative arrays

2017-05-02 Thread evilrat via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So the closest solution is to move initialization of AA to sh

Re: Top level associative arrays

2017-05-02 Thread evilrat via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 09:50:50 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So th

Re: Top level associative arrays

2017-05-02 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-05-02 09:48, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { w

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module ctor as says evilrat but how can I make an immutable a

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 14:37:20 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module

Re: Top level associative arrays

2017-05-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 02, 2017 at 02:37:20PM +, ANtlord via Digitalmars-d-learn wrote: > On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: > > > > Note that when declared as "enum", all places it's referenced, a new > > associative array will be allocated. > > If it is allocated at all plac

  1   2   3   4   >