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: foreach over enums?

2010-10-05 Thread Tomek Sowiński
Simen kjaeraas napisał: > enum X { A=3, B=1, C } > > void main( ) { > foreach( e; __traits(allMembers, X) ) { > writeln( "X.", e, " = ", mixin( "X."~e ) ); > } > } mixin("X."~e) => __traits(getMember, X, e) For mixin-allergics. -- Tomek

Re: Linking D and Obj-C code into a Cocoa app proper? (Mac)

2010-10-05 Thread Heywood Floyd
Ok! Thanks for the advice! Great work on the plugin—it got me into D :) /FH Michel Fortin Wrote: > On 2010-10-05 10:02:45 -0400, Heywood Floyd said: > > > But, sometimes I get reeeaally weird bugs. I had one bug where if I > > added an empty function to a class in D I got EXC_BAD_ACCES (segf

Destruction Sequence: module and classes defined within

2010-10-05 Thread vano
The code below: module used; import std.stdio; class ClassA { this() { writeln("A ctor"); } ~this() { writeln("A dtor"); } } static this() { writeln("used.sctor"); } static ~this() { writeln("used.sdtor"); } void main() { auto a = new Class

Re: Linking D and Obj-C code into a Cocoa app proper? (Mac)

2010-10-05 Thread Michel Fortin
On 2010-10-05 10:02:45 -0400, Heywood Floyd said: But, sometimes I get reeeaally weird bugs. I had one bug where if I added an empty function to a class in D I got EXC_BAD_ACCES (segfault). An empty function! Ie "void f(){}". Remove the function--it works. In the debugger, I got the impressio

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: Are there active D Communities?

2010-10-05 Thread %u
== Quote from Nick B ("nick_NOSPAM_.barbalich"@gmail.com)'s article > there is also the tango community. > check out here: http://www.dsource.org/projects/tango > Also many of these projects have IRC chat rooms, most of them on the > irc.freenode.net server. "d.tango" is the name of the IRC chat r

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

Linking D and Obj-C code into a Cocoa app proper? (Mac)

2010-10-05 Thread Heywood Floyd
Good Evenening Ladies and Gentlemen! == Background == So I currently have a bare-bones Cocoa-app. It's just a window with an OpenGL-view. In the view's draw-function I make the gl-view the current OpenGL context and then call "extern (C) render()". Meanwhile, in a D-file I have the implemen

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

Associative arrays give compile error

2010-10-05 Thread Bob Cowdery
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 constant about this. The example is straight out the book. Using