D vs perl6

2018-11-18 Thread dangbinghoo via Digitalmars-d-learn
hi, What if D compared with the latest perl6? well, I know that perl6 is a VM targeted language. so which has the greater modeling-power? And perl6 seems is selling for Concurrency[1], but I think D will do this far better than a VM targeted language, right? with the pre-released version of

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 19 November 2018 at 02:08:14 UTC, Dennis wrote: On Monday, 19 November 2018 at 01:24:02 UTC, Stanislav Blinov wrote: Yup, that's because, like Rubn said, copying value types is trivial. Where it all comes to bite you is when you start having pointers, because you can't copy a const(T

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 19 November 2018 at 02:03:18 UTC, Dennis wrote: On Monday, 19 November 2018 at 01:13:29 UTC, Stanislav Blinov wrote: You just dismissed that second to last sentence, did you? :) I don't know what you mean with it. It's not that I'm trying to be sneaky or lazy really trying to modif

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 01:24:02 UTC, Stanislav Blinov wrote: Yup, that's because, like Rubn said, copying value types is trivial. Where it all comes to bite you is when you start having pointers, because you can't copy a const(T)* into a T*. I'm not using reference types, but still: `

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 01:13:29 UTC, Stanislav Blinov wrote: You just dismissed that second to last sentence, did you? :) I don't know what you mean with it. It's not that I'm trying to be sneaky or lazy really trying to modify the const parameter when I should treat it properly. And

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 19 November 2018 at 00:50:28 UTC, Dennis wrote: I'm also trying to make it work with immutable, and from BigInt [2] I learned that constructors need to be `pure` for creating immutable objects. (I don't know why.) That's only for types with indirections (pointers), since `pure` gu

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 18 November 2018 at 20:10:52 UTC, Dennis wrote: On Sunday, 18 November 2018 at 18:17:54 UTC, Stanislav Blinov wrote: Q log2(Q)(inout Q num) if (is(Q : q16) || is(Q : q32)) { /* ... */ } Being able to jam mutable/const/immutable implementation in one function like that should tell

Re: opDispatch doesn't play nice with inheritance

2018-11-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 17, 2018 11:09:51 PM MST Carl Sturtivant via Digitalmars-d-learn wrote: > On Thursday, 15 November 2018 at 19:01:45 UTC, Ali Çehreli wrote: > > On 11/15/2018 09:14 AM, Carl Sturtivant wrote: > > > opDispatch is special in that it allows for functions to be > > > > added to a

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 November 2018 at 22:30:52 UTC, Rubn wrote: Yah most people tend to avoid const for this reason. It only really works for basic types, if you have a "const int" you can convert it to an "int" by copy. But if you have a type like Vector!(const int) that won't work, you can't even co

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Rubn via Digitalmars-d-learn
On Sunday, 18 November 2018 at 17:30:18 UTC, Dennis wrote: I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2; // compiles! despite `a` being const. writeln(a); // still 6 a.toQ32 /= 2;// what's actually h

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 November 2018 at 18:17:54 UTC, Stanislav Blinov wrote: // implement separate methods for mutable/const/immutable Thanks. I should have tried that, but I assumed it wouldn't work since you can't overload on return-type only. However, the const / non-const makes it allowed

Re: Neater enum + version

2018-11-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-11-18 18:52, Neia Neutuladh wrote: On Sun, 18 Nov 2018 17:47:07 +, Vladimirs Nordholm wrote: Is there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ; If you're doing it often: T ifPosix(T)(T a, T b) { versio

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 18 November 2018 at 17:30:18 UTC, Dennis wrote: I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2; // compiles! despite `a` being const. Ouch. That's actually kind of nasty. writeln(a); // stil

Re: Neater enum + version

2018-11-18 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Sunday, 18 November 2018 at 17:52:21 UTC, Neia Neutuladh wrote: On Sun, 18 Nov 2018 17:47:07 +, Vladimirs Nordholm wrote: Is there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ; If you're doing it often: T ifPosix(

Re: Neater enum + version

2018-11-18 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 18 Nov 2018 17:47:07 +, Vladimirs Nordholm wrote: > Is there anyway to make it "neater"? Maybe something in one line: > > enum foo = version (Posix) { "posix" } : { "other" } ; If you're doing it often: T ifPosix(T)(T a, T b) { version (Posix) return a; else return b; } enum f

Neater enum + version

2018-11-18 Thread Vladimirs Nordholm via Digitalmars-d-learn
Currently I have something like version (Posix) { enum foo = "bar"; } else { enum foo = "baz"; } Is there anyway to make it "neater"? Maybe something in one line: enum foo = version (Posix) { "posix" } : { "other" } ;

difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2; // compiles! despite `a` being const. writeln(a); // still 6 a.toQ32 /= 2;// what's actually happening ``` My q16 type has an implicit conversion to q32

Re: Making external types available to mixins

2018-11-18 Thread John Chapman via Digitalmars-d-learn
On Saturday, 17 November 2018 at 21:11:38 UTC, Adam D. Ruppe wrote: On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman wrote: Has anyone had a similar need and come up with a solution? You might be able to just pass it the Calendar type, and then fetch its parent module and get the I

Re: How do you debug @safe @nogc code? Can't figure out how to print.

2018-11-18 Thread aliak via Digitalmars-d-learn
On Saturday, 17 November 2018 at 21:56:23 UTC, Neia Neutuladh wrote: On Sat, 17 Nov 2018 21:16:13 +, aliak wrote: Could do. But it's not scalable. I'd have to comment out all the unittests that call the template function with a T that allocates inside the @nogc template (if I understood you

Re: Inconsistency between `AllMembers` and `hasMember`

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
Reported: https://issues.dlang.org/show_bug.cgi?id=19410

Re: Inconsistency between `AllMembers` and `hasMember`

2018-11-18 Thread drug via Digitalmars-d-learn
On 18.11.2018 5:37, Stanislav Blinov wrote: It's only "hidden" in that there's no symbol to access it. But you can still access it via .tupleof, and it still of course affects the ABI (i.e. S.sizeof is always at least pointer size when S is nested). If you want to iterate fields, .tupleof is a

Re: Inconsistency between `AllMembers` and `hasMember`

2018-11-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 18 November 2018 at 09:10:57 UTC, bauss wrote: On Sunday, 18 November 2018 at 02:37:13 UTC, Stanislav Blinov wrote: It's only "hidden" in that there's no symbol to access it... But in that case shouldn't you be able to tell whether it has it or not through hasMember? Yah, a cas

Re: Inconsistency between `AllMembers` and `hasMember`

2018-11-18 Thread bauss via Digitalmars-d-learn
On Sunday, 18 November 2018 at 02:37:13 UTC, Stanislav Blinov wrote: On Sunday, 18 November 2018 at 00:51:51 UTC, drug wrote: On 18.11.2018 1:26, Adam D. Ruppe wrote: That's because the compiler passes it a hidden pointer to refer to the context outside. The compiler could perhaps be smarter