Global immutable AA literals

bearophile bearophileHUGS at lycos.com
Tue Nov 8 22:43:06 PST 2011


Is it possible to modify DMD to allow a program like:


immutable int[int] aa = [1:15, 2: 7];
void main() {}


With the latest DMD it gives:
test.d(1): Error: non-constant expression [1:15,2:7]

Global immutable associative arrays are handy in script-like programs, I use them now and then in Python (despite they are not immutable).
This is a workaround for script-like programs, that I sometimes use:


immutable int[int] aa;
static this() {
    aa = [1:15, 2: 7];
}
void main() {}


But when possible I try to avoid using static this.

Bye,
bearophile


More information about the Digitalmars-d mailing list