Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 22, 2017 at 06:17:14PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Wednesday, 22 February 2017 at 17:05:17 UTC, H. S. Teoh wrote: > > On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via > > Digitalmars-d-learn wrote: > > > [...] > > > > I'm not sure it's that simple.

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 17:05:17 UTC, H. S. Teoh wrote: On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via Digitalmars-d-learn wrote: [...] I'm not sure it's that simple. Just because AA's become CTFEable doesn't mean they will automatically be convertible to object code

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Wednesday, 22 February 2017 at 15:27:22 UTC, H. S. Teoh wrote: > > (In fact, now I'm wondering if we could just hack dmd to emit the > > equivalent of this code as a lowering, whenever the user tries to > >

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 15:27:22 UTC, H. S. Teoh wrote: (In fact, now I'm wondering if we could just hack dmd to emit the equivalent of this code as a lowering, whenever the user tries to declare a compile-time initialized AA.) All the problems disappear if the AA's are compiler

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 22, 2017 at 09:00:36AM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: [...] > You can use an enum to declare the AA and then assign it to an > immutable variable using "static this". The you would only use to the > immutable variable and never the enum. > > enum aa = [1 : 2]; >

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread Daniel Kozak via Digitalmars-d-learn
Yes this is how I mean it. Dne 22. 2. 2017 9:05 napsal uživatel "Jacob Carlborg via Digitalmars-d-learn" : > On 2017-02-21 23:49, H. S. Teoh via Digitalmars-d-learn wrote: > > That may appear to work, but I would *strongly* recommend against it, >> because what

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-22 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-02-21 23:49, H. S. Teoh via Digitalmars-d-learn wrote: That may appear to work, but I would *strongly* recommend against it, because what happens when you use enum with an AA, is that the AA will be created *at runtime*, *every single time* it is referenced. (It is as if you

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 22:34:57 UTC, Chad Joan wrote: In this case the AA isn't actually coded into the executable; but at least the configuration from some_data.csv will be in the executable as a string. The program will construct the AA at startup. It's not as "cool", but it

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 22, 2017 at 12:38:47AM +, Chad Joan via Digitalmars-d-learn wrote: [...] Hmm. It's actually not necessary to manually write a foreach loop to convert an array to an AA. We could, instead, change parseTwoColumnCsv() to return an array of std.typecons.Tuple instead (which,

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 23:30:52 UTC, Chad Joan wrote: On Tuesday, 21 February 2017 at 22:43:15 UTC, H. S. Teoh wrote: Parsing strings at program startup is ugly and slow. What about parsing at compile-time with CTFE into an array literal and transforming that into an AA at startup,

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 22:43:15 UTC, H. S. Teoh wrote: Parsing strings at program startup is ugly and slow. What about parsing at compile-time with CTFE into an array literal and transforming that into an AA at startup, which should be a lot faster? // Warning: untested

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 21, 2017 at 11:50:02PM +0100, Daniel Kozak via Digitalmars-d-learn wrote: > I have similar issue and I beleive I was able to workaround that > somehow, but it is so many years now :(. Have you tried enum > dataLookup instead of immutable string[string] dataLookup That may appear to

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Daniel Kozak via Digitalmars-d-learn
I have similar issue and I beleive I was able to workaround that somehow, but it is so many years now :(. Have you tried enum dataLookup instead of immutable string[string] dataLookup Dne 21.2.2017 v 22:53 Chad Joan via Digitalmars-d-learn napsal(a): Hello all, I'm trying to make this work:

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 21, 2017 at 10:34:57PM +, Chad Joan via Digitalmars-d-learn wrote: > On Tuesday, 21 February 2017 at 22:26:01 UTC, Chad Joan wrote: > > On Tuesday, 21 February 2017 at 21:58:07 UTC, Stefan Koch wrote: > > > On Tuesday, 21 February 2017 at 21:53:23 UTC, Chad Joan wrote: > > > >

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 22:26:01 UTC, Chad Joan wrote: On Tuesday, 21 February 2017 at 21:58:07 UTC, Stefan Koch wrote: On Tuesday, 21 February 2017 at 21:53:23 UTC, Chad Joan wrote: Hello all, I'm trying to make this work: [...] You cannot create AA's at ctfe and carry them over

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 21:58:07 UTC, Stefan Koch wrote: On Tuesday, 21 February 2017 at 21:53:23 UTC, Chad Joan wrote: Hello all, I'm trying to make this work: [...] You cannot create AA's at ctfe and carry them over to runtime use. You'd have to use a costum dictionary-type. I

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 21:53:23 UTC, Chad Joan wrote: Hello all, I'm trying to make this work: [...] You cannot create AA's at ctfe and carry them over to runtime use. You'd have to use a costum dictionary-type. I think the vibe.d project has one you could use.

How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
Hello all, I'm trying to make this work: --- pure string[string] parseTwoColumnCsv(string inputCsv) { import std.csv; import std.typecons; string[string] result; foreach ( record; csvReader!(Tuple!(string,string))(inputCsv) )