Re: How to initialize a associative array?

2016-12-24 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote: On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: What's the correct way? You cannot initialize an AA at compile-time. Because AA's are provided by druntime and the ABI is not stable. For fun I'm throwing toge

Re: How to initialize a associative array?

2016-12-24 Thread Carl Vogel via Digitalmars-d-learn
On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote: You cannot initialize an AA at compile-time. Because AA's are provided by druntime and the ABI is not stable. This bit me when I was first starting out as well. I feel like there's really very little documentation on this, and

Re: Runtime error trying to call opCall on variant array of objects

2016-12-24 Thread Ali Çehreli via Digitalmars-d-learn
On 12/24/2016 08:36 AM, aliak wrote: "Cannot apply `()' to a value of type `Command!(__lambda1, int)". I think it's failing when it checks for "!isFunctionPointer!A && !isDelegate!A". Storing delegates is a workaround. Three notes in the code: // (1) Added imports import std.variant; import s

Re: DMD Stdio Linker Oddities

2016-12-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 24 December 2016 at 19:58:45 UTC, Jake Pittis wrote: I'm posting this in Learn because I'm assuming I've done something wrong rather than discovered a bug. You need to pass all modules you use to the linker somehow. Easiest is to `dmd main.d linking_succeeds.d linking_fails.d` ju

DMD Stdio Linker Oddities

2016-12-24 Thread Jake Pittis via Digitalmars-d-learn
I'm posting this in Learn because I'm assuming I've done something wrong rather than discovered a bug. Running `dmd -main main.d` with the following 3 files produces the following linker error. ``` $ dmd -main main.d Undefined symbols for architecture x86_64: "_D13linking_fails12__ModuleInf

Runtime error trying to call opCall on variant array of objects

2016-12-24 Thread aliak via Digitalmars-d-learn
Hey, so I'm trying to make an variant array of objects (each one has an opCall defined) and then call each of them in succession. It doesn't seem to be working. The error I get is: "Cannot apply `()' to a value of type `Command!(__lambda1, int)". I think it's failing when it checks for "!isFun

Re: Recursive-descent parsing

2016-12-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 December 2016 at 12:42:31 UTC, Andrew Edwards wrote: The authors of "The Art of Java" present, as a first coding example, a recursive-descent parser to demonstrate Java's ability to facilitate low level programming commonly performed in C and C++. I took the opportunity to por

Recursive-descent parsing

2016-12-24 Thread Andrew Edwards via Digitalmars-d-learn
The authors of "The Art of Java" present, as a first coding example, a recursive-descent parser to demonstrate Java's ability to facilitate low level programming commonly performed in C and C++. I took the opportunity to port the code to D. By doing this, I now have an understanding of how a

Re: How to initialize a associative array?

2016-12-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable'). What's the correct way? You cannot initialize an AA at compile-time.