Taming templates and mixin magic: type inpector helper in D/Phobos?

2018-04-03 Thread Carlos Navarro via Digitalmars-d-learn
As a newbie in D (and making a lots of mistakes), I've found myself relying heavily in the use of a rudimentary type inspector to visualize my templated code instantiations. It's simple and incomplete as hell but good enough to see what happens under the hood quickly. QUESTION: Is there a func

Re: Learning D - modules packages and the package.d

2018-04-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 04, 2018 04:54:50 Ali via Digitalmars-d-learn wrote: > I am going through the Learning D book by Michael Parker > So every now and then I will make post about the book > either critics of the book, book content or questions > > > First critic > chapter 2 - the special package mo

Re: Learning D - modules packages and the package.d

2018-04-03 Thread Ali via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 04:54:50 UTC, Ali wrote: at first i though package.d is special name, as in i must call the file package.d or this trick or idiom to work the trick was to have one module that public import all the modules you import as group in other modules so instead of impor

Learning D - modules packages and the package.d

2018-04-03 Thread Ali via Digitalmars-d-learn
I am going through the Learning D book by Michael Parker So every now and then I will make post about the book either critics of the book, book content or questions First critic chapter 2 - the special package module this small section, suggest an idiom to create a package which can have any n

Re: is this even possible? newbie + mixin template + foreach (allMembers)

2018-04-03 Thread Seb via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 18:49:00 UTC, Carlos Navarro wrote: QUESTION: Obviously I'm no geting mixins/templates nor traits and I'm failing miserably to find/identify the right examples or documentation to help me tackle this thing. What is wrong in this code? is this pattern sintactically

Re: Better way to append to array than ~= ?

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 20:02:46 UTC, Vladimirs Nordholm wrote: On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote: On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: [...] In this specific case, since you know the length of `Args`, you can pre-allocate an array of tha

Re: Better way to append to array than ~= ?

2018-04-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 20:02:46 UTC, Vladimirs Nordholm wrote: On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote: On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: [...] In this specific case, since you know the length of `Args`, you can pre-allocate an array of tha

Re: Better way to append to array than ~= ?

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote: On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: [...] In this specific case, since you know the length of `Args`, you can pre-allocate an array of that size and loop through it doing your initialization. However, if

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:41:54 UTC, Alex wrote: On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: [...] Would labelling help? https://run.dlang.io/is/vE1KyD Ah! Okay, now I see. Thanks Alex and Adam!

Re: Better way to append to array than ~= ?

2018-04-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: Hello people. I currently have a function which multiple times per second takes in arguments, and appends the argument as my special type. The following code should explain what I do more properly: struct MySpecialType {

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: switch(foo) Put the label on the switch whatever: switch(foo) mixin(format(" case Foo.%s:bar = Bar.%s;break; ", f, f)); then use the label here break whatever;

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: My base problem is that I want to mixin `break` into a switch statement, but the mixin is within a static foreach. Take a look at the following code: switch(foo) { static foreach(f; EnumMembers!Foo) {

mixin break; in switch containing static foreach

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
My base problem is that I want to mixin `break` into a switch statement, but the mixin is within a static foreach. Take a look at the following code: switch(foo) { static foreach(f; EnumMembers!Foo) { mixin(format(" case Foo.%s:bar = Bar.%

Re: is this even possible? newbie + mixin template + foreach (allMembers)

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 18:57:29 UTC, WebFreak001 wrote: you need to use a static foreach for this. You can insert a static foreach basically where you can insert a function definition like void foo() {} foreach is more like a function call like foo(), so you can't put it in the mixin t

Better way to append to array than ~= ?

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
Hello people. I currently have a function which multiple times per second takes in arguments, and appends the argument as my special type. The following code should explain what I do more properly: struct MySpecialType { char c; } auto foo(Args...)(Args args) { MySpecialT

Re: is this even possible? newbie + mixin template + foreach (allMembers)

2018-04-03 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 18:49:00 UTC, Carlos Navarro wrote: QUESTION: Obviously I'm no geting mixins/templates nor traits and I'm failing miserably to find/identify the right examples or documentation to help me tackle this thing. What is wrong in this code? is this pattern sintactically

Re: @property for simple methods?

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Monday, 2 April 2018 at 15:05:04 UTC, Seb wrote: On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: On Monday, 2 April 2018 at 14:20:49 UTC, Dennis wrote: [...] Ah! First time I read the docs I didn't understand the typeof(exp) explanation, but yours made me understand tha

is this even possible? newbie + mixin template + foreach (allMembers)

2018-04-03 Thread Carlos Navarro via Digitalmars-d-learn
QUESTION: Obviously I'm no geting mixins/templates nor traits and I'm failing miserably to find/identify the right examples or documentation to help me tackle this thing. What is wrong in this code? is this pattern sintactically possible? what I'm getting wrong? CONTEXT: I'm a newbie trying

Re: @property for simple methods?

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Monday, 2 April 2018 at 15:15:05 UTC, Dennis wrote: On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ? You're probably fine either way, it's mostly for makin

Second Language Acquisition - Dogme & Direct Method

2018-04-03 Thread markmst via Digitalmars-d-learn
The Dogme method, based on the writing of Scott Thornbury, “considers language learning to be a process where language emerges rather than one where it is acquired”. The entire method is based on conversation and the teaching (or in group lessons ‘moderation’) as such does not follow specific s

Re: How to Stay Away From Faux Pas in a Foreign Language?

2018-04-03 Thread Timoses via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 15:02:34 UTC, markmst wrote: Why Pay For Learning a Foreign I actually read this until "Why Pay For Learning a Foreign Language". I didn't get the joke... Go figure..

How to Stay Away From Faux Pas in a Foreign Language?

2018-04-03 Thread markmst via Digitalmars-d-learn
Many language learners will have a similar story to narrate. They have often used a foreign word accidentally, which may sound similar in the English as well as in the target language and yet are completely different in their meanings, Such linguistic goof-ups are referred to as "false friends"

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-03 Thread Timoses via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 13:12:05 UTC, Timoses wrote: On Tuesday, 3 April 2018 at 05:20:55 UTC, Seb wrote: Better diagnostics and error messages is a key goal in 2018 for dmd ;-) Awesome! How about telling the user which of the template constraints failed? Would be so awesome. Currently, t

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-03 Thread Timoses via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 05:20:55 UTC, Seb wrote: Better diagnostics and error messages is a key goal in 2018 for dmd ;-) Awesome! How about telling the user which of the template constraints failed? Would be so awesome. Currently, there's a need to check every single one (as mentioned by

Re: What is the equivalent of C++'s std::optional and std::nullopt in D?

2018-04-03 Thread Timoses via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:10:09 UTC, helxi wrote: For reference: https://en.cppreference.com/w/cpp/utility/optional See also this topic recently discussed: https://forum.dlang.org/post/p9qvb8$1j1n$1...@digitalmars.com

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-03 Thread Eduard Staniloiu via Digitalmars-d-learn
On Monday, 2 April 2018 at 21:32:47 UTC, Steven Schveighoffer wrote: On 4/2/18 5:16 PM, Per Nordlöw wrote: On Monday, 2 April 2018 at 20:43:01 UTC, Alexandru Jercaianu wrote: I am not completely sure how to solve this, but maybe we can find some clues here [1]. It seems like we should use addRo