Re: Associative arrays give compile error

2010-10-06 Thread Steven Schveighoffer
On Wed, 06 Oct 2010 08:12:28 -0400, bearophile wrote: Steven Schveighoffer: Casting to immutable is the only way to create such a beast. Then maybe we have to improve the language semantics to allow a better solution. See the Transients of Clojure or the larval objects of Java :-) The

Re: Associative arrays give compile error

2010-10-06 Thread bearophile
Steven Schveighoffer: > Casting to immutable is the only way to create such a beast. Then maybe we have to improve the language semantics to allow a better solution. See the Transients of Clojure or the larval objects of Java :-) The compiler may need to test (at compile time) that there's only

Re: Associative arrays give compile error

2010-10-06 Thread Steven Schveighoffer
On Tue, 05 Oct 2010 22:02:30 -0400, bearophile wrote: Denis Koroskin: Compute mutable copy and then cast to immutable. Am I missing something? That's possible. But it's an exceptionally dirty thing, I am not sure it works in SafeD. A well designed const system has to offer a more clean

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Wed, 06 Oct 2010 06:02:30 +0400, bearophile wrote: Denis Koroskin: Compute mutable copy and then cast to immutable. Am I missing something? That's possible. But it's an exceptionally dirty thing, I am not sure it works in SafeD. A well designed const system has to offer a more clean

Re: Associative arrays give compile error

2010-10-05 Thread bearophile
Denis Koroskin: > Compute mutable copy and then cast to immutable. Am I missing something? That's possible. But it's an exceptionally dirty thing, I am not sure it works in SafeD. A well designed const system has to offer a more clean solution :-) Do you agree? Bye, bearophile

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Wed, 06 Oct 2010 04:14:37 +0400, bearophile wrote: Denis Koroskin: I found the following to work fine: K[V] assocArray = createAssocArray(); K[V] createAssocArray() { K[V] assocArray = [ k1: v1, k2: v2, ... ]; return assocArray; } Thank you for

Re: Associative arrays give compile error

2010-10-05 Thread bearophile
Denis Koroskin: > I found the following to work fine: > > K[V] assocArray = createAssocArray(); > > K[V] createAssocArray() > { > K[V] assocArray = [ > k1: v1, > k2: v2, > ... > ]; > > return assocArray; > } Thank you for your answer. But I need to comput

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Wed, 06 Oct 2010 03:45:11 +0400, bearophile wrote: /*immutable*/ E_MODE[string] a_mode; static this () { foreach (m; __traits(allMembers, E_MODE)) mixin(`a_mode["` ~ m ~ `"] = E_MODE.` ~ m ~ `;`); } How do you build an immutable AA that is global or local to a function? Bye

Re: Associative arrays give compile error

2010-10-05 Thread bearophile
> /*immutable*/ E_MODE[string] a_mode; > > static this () { > foreach (m; __traits(allMembers, E_MODE)) > mixin(`a_mode["` ~ m ~ `"] = E_MODE.` ~ m ~ `;`); > } How do you build an immutable AA that is global or local to a function? Bye, bearophile

Re: Associative arrays give compile error

2010-10-05 Thread bearophile
> enum E_MODE { > LSB, // 0 > USB, // 1 > DSB, // 2 > CWL, // 3 > CWU, // 4 > FMN, // 5 > AM, // 6 > DIGU, // 7 > SPEC, // 8 > DIGL, // 9 > SAM, // 10 > DRM // 11 > } > > void main() { > // associative array for translation >

Re: Associative arrays give compile error

2010-10-05 Thread bearophile
Denis Koroskin: > import std.stdio; > import std.typecons; > > void main() > { > auto aa = ["hello": tuple(100.0, 6100.0)]; > auto result = aa["hello"]; > > writeln(result.field[0], " ", result._1); // primary and alternative way > } Now Tuples accept the natural syntax

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 15:14, Steven Schveighoffer wrote: > On Tue, 05 Oct 2010 09:00:13 -0400, Bob Cowdery > wrote: > >> On 05/10/2010 13:45, Denis Koroskin wrote: > >>> "static this" is called a static constructor and can be used for >>> classes and modules. The code in static constructor is guarantied

Re: Associative arrays give compile error

2010-10-05 Thread Steven Schveighoffer
On Tue, 05 Oct 2010 09:00:13 -0400, Bob Cowdery wrote: On 05/10/2010 13:45, Denis Koroskin wrote: "static this" is called a static constructor and can be used for classes and modules. The code in static constructor is guarantied to be called before you use that class/module, it usually ha

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 17:00:13 +0400, Bob Cowdery wrote: On 05/10/2010 13:45, Denis Koroskin wrote: On Tue, 05 Oct 2010 16:32:14 +0400, Bob Cowdery wrote: On 05/10/2010 13:05, Denis Koroskin wrote: On Tue, 05 Oct 2010 15:53:55 +0400, Denis Koroskin <2kor...@gmail.com> wrote: On Tue, 05

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 13:45, Denis Koroskin wrote: > On Tue, 05 Oct 2010 16:32:14 +0400, Bob Cowdery > wrote: > >> On 05/10/2010 13:05, Denis Koroskin wrote: >>> On Tue, 05 Oct 2010 15:53:55 +0400, Denis Koroskin <2kor...@gmail.com> >>> wrote: >>> On Tue, 05 Oct 2010 15:40:39 +0400, Bob Cowdery >>>

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 16:32:14 +0400, Bob Cowdery wrote: On 05/10/2010 13:05, Denis Koroskin wrote: On Tue, 05 Oct 2010 15:53:55 +0400, Denis Koroskin <2kor...@gmail.com> wrote: On Tue, 05 Oct 2010 15:40:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:13, Denis Koroskin wrote: On Tue, 05

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 13:05, Denis Koroskin wrote: > On Tue, 05 Oct 2010 15:53:55 +0400, Denis Koroskin <2kor...@gmail.com> > wrote: > >> On Tue, 05 Oct 2010 15:40:39 +0400, Bob Cowdery >> wrote: >> >>> On 05/10/2010 12:13, Denis Koroskin wrote: On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 15:53:55 +0400, Denis Koroskin <2kor...@gmail.com> wrote: On Tue, 05 Oct 2010 15:40:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:13, Denis Koroskin wrote: On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:04, Denis Koroskin wrote: On Tue,

Re: Associative arrays give compile error

2010-10-05 Thread Lars T. Kyllingstad
On Tue, 05 Oct 2010 12:50:44 +0100, Bob Cowdery wrote: > On 05/10/2010 12:40, Bob Cowdery wrote: >> On 05/10/2010 12:13, Denis Koroskin wrote: >>> On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery >>> wrote: >>> On 05/10/2010 12:04, Denis Koroskin wrote: > On Tue, 05 Oct 2010 14:57:22 +0

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 15:50:44 +0400, Bob Cowdery wrote: On 05/10/2010 12:40, Bob Cowdery wrote: On 05/10/2010 12:13, Denis Koroskin wrote: On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:04, Denis Koroskin wrote: On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 15:40:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:13, Denis Koroskin wrote: On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:04, Denis Koroskin wrote: On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery wrote: On 05/10/2010 11:45, Denis Koro

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 12:40, Bob Cowdery wrote: > On 05/10/2010 12:13, Denis Koroskin wrote: >> On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery >> wrote: >> >>> On 05/10/2010 12:04, Denis Koroskin wrote: On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery wrote: > On 05/10/2010 11:45,

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 12:13, Denis Koroskin wrote: > On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery > wrote: > >> On 05/10/2010 12:04, Denis Koroskin wrote: >>> On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery >>> wrote: >>> On 05/10/2010 11:45, Denis Koroskin wrote: > On Tue, 05 Oct 2010 14:

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 15:08:39 +0400, Bob Cowdery wrote: On 05/10/2010 12:04, Denis Koroskin wrote: On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery wrote: On 05/10/2010 11:45, Denis Koroskin wrote: On Tue, 05 Oct 2010 14:23:47 +0400, Bob Cowdery wrote: I can't seem to get any sense o

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 12:04, Denis Koroskin wrote: > On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery > wrote: > >> On 05/10/2010 11:45, Denis Koroskin wrote: >>> On Tue, 05 Oct 2010 14:23:47 +0400, Bob Cowdery >>> wrote: >>> I can't seem to get any sense out of associative arrays. Even the s

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 14:57:22 +0400, Bob Cowdery wrote: On 05/10/2010 11:45, Denis Koroskin wrote: On Tue, 05 Oct 2010 14:23:47 +0400, Bob Cowdery wrote: I can't seem to get any sense out of associative arrays. Even the simplest definition won't compile so I must be doing something daft.

Re: Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
On 05/10/2010 11:45, Denis Koroskin wrote: > On Tue, 05 Oct 2010 14:23:47 +0400, Bob Cowdery > wrote: > >> I can't seem to get any sense out of associative arrays. Even the >> simplest definition won't compile so I must be doing something daft. >> >> int[string] aa = ["hello":42]; >> >> Error: n

Re: Associative arrays give compile error

2010-10-05 Thread Denis Koroskin
On Tue, 05 Oct 2010 14:23:47 +0400, Bob Cowdery wrote: I can't seem to get any sense out of associative arrays. Even the simplest definition won't compile so I must be doing something daft. int[string] aa = ["hello":42]; Error: non-constant expression ["hello":42] What exactly is not cons