January 08, 2015
On Thursday, 8 January 2015 at 11:43:30 UTC, ponce wrote:
> On Thursday, 8 January 2015 at 11:41:43 UTC, Szymon Gatner wrote:
>>>> 
>>>> Question:
>>>> 
>>>> Where did this syntax came from? It is not documented for 'import' keyword.(first time I see that D has built-in resource compiler):
>>>> 
>>>> ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");
>>> it is documented: http://dlang.org/expression.html#ImportExpression
>>> it's a nice D habit of overloading keywords.
>>
>> Ah, thanks. Follow up then: can such imported string be used for mixin?
>
> Yes.

That is pretty damn cool then.
January 08, 2015
On Thu, 08 Jan 2015 11:41:42 +0000
Szymon Gatner via Digitalmars-d-announce
<digitalmars-d-announce@puremagic.com> wrote:

> On Thursday, 8 January 2015 at 11:31:14 UTC, ketmar via Digitalmars-d-announce wrote:
> > On Thu, 08 Jan 2015 11:24:34 +0000
> > Szymon Gatner via Digitalmars-d-announce
> > <digitalmars-d-announce@puremagic.com> wrote:
> >
> >> On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
> >> > I've started a list of curated D tips and tricks here: http://p0nce.github.io/d-idioms/
> >> >
> >> > Anything that you wished you learned earlier at one point in the D world is welcome to be added or suggested.
> >> >
> >> > I think the focus should be on "stuff that could make you more productive, or is just funky" but that is up to debate.
> >> >
> >> > Of course the D Cookbook still stays irreplaceable for a consistent, in-depth discussion of being D-enabled.
> >> >
> >> > Thoughts?
> >> 
> >> They are really cool, thanks :)
> >> 
> >> Question:
> >> 
> >> Where did this syntax came from? It is not documented for 'import' keyword.(first time I see that D has built-in resource compiler):
> >> 
> >> ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");
> > it is documented:
> > http://dlang.org/expression.html#ImportExpression
> > it's a nice D habit of overloading keywords.
> 
> Ah, thanks. Follow up then: can such imported string be used for mixin?
sure. either directly, or you can use CTFE to parse imported data and generate code. for now it's somewhat limited, 'cause CTFE parsing eats alot of memory, but when we'll have 128GB of RAM at bare minimum... i don't think that i'll be using external preprocessors to generate D code from various text and binary files.


January 08, 2015
that a really nice idea, thanks.

substring position, std.string.(last)indexOf(|Any|Neither) may be better


btw. this should move to the dlang wiki. Any takers?
January 08, 2015
On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
> I've started a list of curated D tips and tricks here: http://p0nce.github.io/d-idioms/
>
> Anything that you wished you learned earlier at one point in the D world is welcome to be added or suggested.
>
> I think the focus should be on "stuff that could make you more productive, or is just funky" but that is up to debate.
>
> Of course the D Cookbook still stays irreplaceable for a consistent, in-depth discussion of being D-enabled.
>
> Thoughts?

"Struct inheritance with alias this"
You are using a class ;)
January 08, 2015
A note:

a resource compiler is still useful for things like giving a Windows program an icon or other such things where the operating system needs to find the data, since the OS doesn't know how D stores info.

(a fun project that I'm kinda tempted to do some day btw: make program that CAN fetch imported data from a D program. Maybe reading the executable, or maybe establishing a command line protocol to fetch it with the program's help. )

You can compile resources on Windows in D exactly the same way as in C.



Another thing too, I'm starting work on a "This week in D" thing and tips like these are one of the things I'd like to put in it. I guess I don't have anything else to say about it right now, I still have some more prep work to do, but if any of you have idioms or tricks, we should compile a list for reference and perhaps slightly longer articles about their use we can stick in the newsletter. (I'm thinking the length should only be 2-5 paragraphs.)
January 08, 2015
On Thu, 08 Jan 2015 10:21:25 +0000
ponce via Digitalmars-d-announce <digitalmars-d-announce@puremagic.com>
wrote:

> I've started a list of curated D tips and tricks here: http://p0nce.github.io/d-idioms/
> 
> Anything that you wished you learned earlier at one point in the D world is welcome to be added or suggested.
> 
> I think the focus should be on "stuff that could make you more productive, or is just funky" but that is up to debate.
> 
> Of course the D Cookbook still stays irreplaceable for a consistent, in-depth discussion of being D-enabled.
> 
> Thoughts?
i'm not sure, but maybe it worth renaming "struct inheritance" to "extending a struct"? or even something completely different. what it does is actually extending/augmenting the struct, but not OO-inheritance, as one cannot pass "augmented" struct to the function which expects original struct. at least without hackery.


January 08, 2015
On Thursday, 8 January 2015 at 20:16:24 UTC, Adam D. Ruppe wrote:
> Another thing too, I'm starting work on a "This week in D" thing and tips like these are one of the things I'd like to put in it. I guess I don't have anything else to say about it right now, I still have some more prep work to do, but if any of you have idioms or tricks, we should compile a list for reference and perhaps slightly longer articles about their use we can stick in the newsletter. (I'm thinking the length should only be 2-5 paragraphs.)

Feel free to take and extend :)
January 08, 2015
On Thursday, 8 January 2015 at 20:23:11 UTC, ketmar via Digitalmars-d-announce wrote:
> i'm not sure, but maybe it worth renaming "struct inheritance" to
> "extending a struct"? or even something completely different. what it
> does is actually extending/augmenting the struct, but not
> OO-inheritance, as one cannot pass "augmented" struct to the function
> which expects original struct. at least without hackery.

Renamed, thanks!
January 08, 2015
On 01/08/15 21:23, ketmar via Digitalmars-d-announce wrote:
> i'm not sure, but maybe it worth renaming "struct inheritance" to "extending a struct"? or even something completely different. what it does is actually extending/augmenting the struct, but not OO-inheritance, as one cannot pass "augmented" struct to the function which expects original struct. at least without hackery.

'alias this' is just the D syntax for implicit conversions. The feature /is/ crippled, but there's no need for "hackery"; at least not for simple things like that.

   struct A { int a; }
   struct B { A a; alias a this; string b; }

   int f(A a) { return a.a+1; }
   int g(ref A a) { return a.a+1; }
   ref A h(ref A a) { return a; }

   int main() {
      B b;
      return f(b)+g(b)+h(b).a;
   }

artur
January 08, 2015
On Thursday, 8 January 2015 at 20:00:11 UTC, Foo wrote:
> On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
>> I've started a list of curated D tips and tricks here: http://p0nce.github.io/d-idioms/
>>
>> Anything that you wished you learned earlier at one point in the D world is welcome to be added or suggested.
>>
>> I think the focus should be on "stuff that could make you more productive, or is just funky" but that is up to debate.
>>
>> Of course the D Cookbook still stays irreplaceable for a consistent, in-depth discussion of being D-enabled.
>>
>> Thoughts?
>
> "Struct inheritance with alias this"
> You are using a class ;)

And the public label is redundant.