Re: How to initialize a associative array?

2016-12-25 Thread Jack Applegame 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? This works: void main() { immutable

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

2016-12-25 Thread aliak via Digitalmars-d-learn
On Saturday, 24 December 2016 at 23:06:25 UTC, Ali Çehreli wrote: auto c = Command!(fun, Args)(args); writefln("Created %s", c); // (3) Workaround: Storing delegates, not Command instances. return () => c(); Ah, yes. Nice work around :) Thankies!

Re: Is there anything other than nullable to work with optional types?

2016-12-25 Thread ali ak via Digitalmars-d-learn
On Sunday, 25 December 2016 at 20:01:21 UTC, Stefan Koch wrote: Well there is one easy way to do this. pass a pointer to the data. Another easy one is the definition of one invalid set of values and using that is initial value and for convenience overload opCast(T:bool) to check against that

Re: Is there anything other than nullable to work with optional types?

2016-12-25 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 25 December 2016 at 19:22:10 UTC, aliak wrote: Hey, So, been using the programming language swift for a while now, the optional types[1] they support makes working with maybe-type (ala haskell) values extremely pleasant. [...] Well there is one easy way to do this. pass a

Re: Is there anything other than nullable to work with optional types?

2016-12-25 Thread aliak via Digitalmars-d-learn
On Sunday, 25 December 2016 at 20:11:50 UTC, Seb wrote: On Sunday, 25 December 2016 at 19:22:10 UTC, aliak wrote: or is there a way for it to not be so cumbersome to work with? You might be interested in https://github.com/dlang/phobos/pull/3915 Yes! That! Seems like that PR is on a

Is there anything other than nullable to work with optional types?

2016-12-25 Thread aliak via Digitalmars-d-learn
Hey, So, been using the programming language swift for a while now, the optional types[1] they support makes working with maybe-type (ala haskell) values extremely pleasant. Does D have anything other than the Nullable template that can be used to work with optionals, or is there a way for

Re: Is there anything other than nullable to work with optional types?

2016-12-25 Thread Seb via Digitalmars-d-learn
On Sunday, 25 December 2016 at 19:22:10 UTC, aliak wrote: or is there a way for it to not be so cumbersome to work with? You might be interested in https://github.com/dlang/phobos/pull/3915 And https://github.com/dlang/phobos/pull/4989

Re: Is there anything other than nullable to work with optional types?

2016-12-25 Thread Seb via Digitalmars-d-learn
On Sunday, 25 December 2016 at 22:21:17 UTC, aliak wrote: On Sunday, 25 December 2016 at 20:11:50 UTC, Seb wrote: On Sunday, 25 December 2016 at 19:22:10 UTC, aliak wrote: or is there a way for it to not be so cumbersome to work with? You might be interested in