Re: How to make a global immutable associative array?

2014-03-19 Thread Don
On Wednesday, 19 March 2014 at 09:12:53 UTC, Dicebot wrote: On Wednesday, 19 March 2014 at 02:52:23 UTC, bearophile wrote: Rikki Cattermole: Is an enum not appropriate? Because it can be used to push constants and available at ctfe. enum int[int] aa = [1: 2, 3: 4]; pragma(msg, aa); This is

Re: How to make a global immutable associative array?

2014-03-19 Thread Rikki Cattermole
On Wednesday, 19 March 2014 at 09:12:53 UTC, Dicebot wrote: On Wednesday, 19 March 2014 at 02:52:23 UTC, bearophile wrote: Rikki Cattermole: Is an enum not appropriate? Because it can be used to push constants and available at ctfe. enum int[int] aa = [1: 2, 3: 4]; pragma(msg, aa); This is

Re: How to make a global immutable associative array?

2014-03-19 Thread Dicebot
On Wednesday, 19 March 2014 at 02:52:23 UTC, bearophile wrote: Rikki Cattermole: Is an enum not appropriate? Because it can be used to push constants and available at ctfe. enum int[int] aa = [1: 2, 3: 4]; pragma(msg, aa); This is bad from an efficiency point of view. I think Don even sugg

Re: How to make a global immutable associative array?

2014-03-18 Thread Rikki Cattermole
On Wednesday, 19 March 2014 at 04:10:21 UTC, Meta wrote: On Wednesday, 19 March 2014 at 01:56:35 UTC, Rikki Cattermole wrote: Is an enum not appropriate? Because it can be used to push constants and available at ctfe. enum int[int] aa = [1: 2, 3: 4]; pragma(msg, aa); This will create a new a

Re: How to make a global immutable associative array?

2014-03-18 Thread Meta
On Wednesday, 19 March 2014 at 01:56:35 UTC, Rikki Cattermole wrote: Is an enum not appropriate? Because it can be used to push constants and available at ctfe. enum int[int] aa = [1: 2, 3: 4]; pragma(msg, aa); This will create a new associative array at runtime wherever aa is used, rather t

Re: How to make a global immutable associative array?

2014-03-18 Thread bearophile
Rikki Cattermole: Is an enum not appropriate? Because it can be used to push constants and available at ctfe. enum int[int] aa = [1: 2, 3: 4]; pragma(msg, aa); This is bad from an efficiency point of view. I think Don even suggested to disallow it. Bye, bearophile

Re: How to make a global immutable associative array?

2014-03-18 Thread Rikki Cattermole
On Wednesday, 19 March 2014 at 00:16:31 UTC, dnspies wrote: I want to create a global immutable associative array and have it be accessible from anywhere at compile-time. How can I do that? With: immutable int[int] aa = [1:2,3:4]; I get: source/thing.d(1): Error: non-constant expression [1:2

Re: How to make a global immutable associative array?

2014-03-18 Thread bearophile
Dan Killebrew: I meant something else. Why doesn't this work: immutable int[int] aa = [1:2,3:4]; Seems like it should work to me. After all, this works: immutable int[] a = [1,2,3,4]; So how is the second 'more constant' than the first? The fact that the first code block does not compile se

Re: How to make a global immutable associative array?

2014-03-18 Thread Dan Killebrew
On Wednesday, 19 March 2014 at 00:37:27 UTC, bearophile wrote: Dan Killebrew: Seems unintuitive and roundabout. Is this a bug or a feature? It's a good feature. Generally immutable variables are initializable from strongly pure functions. If you think about what immutability and purity mean

Re: How to make a global immutable associative array?

2014-03-18 Thread bearophile
Dan Killebrew: Seems unintuitive and roundabout. Is this a bug or a feature? It's a good feature. Generally immutable variables are initializable from strongly pure functions. If you think about what immutability and purity mean, it's a good match. Bye, bearophile

Re: How to make a global immutable associative array?

2014-03-18 Thread bearophile
dnspies: I want to create a global immutable associative array and have it be accessible from anywhere at compile-time. How can I do that? With: immutable int[int] aa = [1:2,3:4]; I get: source/thing.d(1): Error: non-constant expression [1:2, 3:4] And with: immutable int[int] aa; static t

Re: How to make a global immutable associative array?

2014-03-18 Thread Dan Killebrew
You just have to construct it first and then claim that it is unique and so safely cast it to immutable: import std.exception : assumeUnique; immutable int[int] aa; static this(){ auto temp = [1:2, 3:4]; aa = assumeUnique(temp); } Seems unintuitive and roundabout. Is this a bug or a f

Re: How to make a global immutable associative array?

2014-03-18 Thread Infiltrator
On Wednesday, 19 March 2014 at 00:16:31 UTC, dnspies wrote: I want to create a global immutable associative array and have it be accessible from anywhere at compile-time. How can I do that? With: immutable int[int] aa = [1:2,3:4]; I get: source/thing.d(1): Error: non-constant expression [1:2

How to make a global immutable associative array?

2014-03-18 Thread dnspies
I want to create a global immutable associative array and have it be accessible from anywhere at compile-time. How can I do that? With: immutable int[int] aa = [1:2,3:4]; I get: source/thing.d(1): Error: non-constant expression [1:2, 3:4] And with: immutable int[int] aa; static this(){