January 15, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | >> As for Orange, is it OK with you if I show a small part of it? Is it OK for me to link to the github project? > > Sure, go ahead and use whatever you want :) Thanks. >> Btw, I think that by using the technics shown in Nick's last year article (generating switch/cases from CT information), it would be possible to make some parameters of Reflection.d be runtime parameters instead of compile-time. > > > Do you have a link? Sure: http://www.semitwist.com/articles/EfficientAndFlexible/SinglePage/#part6-3 |
January 15, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Sun, Jan 15, 2012 at 17:00, Ali Çehreli <acehreli@yahoo.com> wrote: >> I do think a big range tutorial is overdue. Andrei's article is good, but we need something a bit more detailed / for newbies > > > I am hoping that this is good enough for now: > > http://ddili.org/ders/d.en/ranges.html It sure is! This should be advertised somehow. Maybe add a link in the D Wiki? http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial I think many chapters of your book could be linked in there. by the by, I added a Resources appendix, where I cite your chapter on templates. Philippe |
January 16, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | On 1/15/12 4:19 PM, Philippe Sigaud wrote:
> On Sun, Jan 15, 2012 at 17:00, Ali Çehreli<acehreli@yahoo.com> wrote:
>
>>> I do think a big range tutorial is overdue. Andrei's article is good,
>>> but we need something a bit more detailed / for newbies
>>
>>
>> I am hoping that this is good enough for now:
>>
>> http://ddili.org/ders/d.en/ranges.html
>
> It sure is! This should be advertised somehow.
Should I redditize?
Andrei
|
January 16, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 01/15/2012 04:34 PM, Andrei Alexandrescu wrote:
> On 1/15/12 4:19 PM, Philippe Sigaud wrote:
>> On Sun, Jan 15, 2012 at 17:00, Ali Çehreli<acehreli@yahoo.com> wrote:
>>
>>>> I do think a big range tutorial is overdue. Andrei's article is good,
>>>> but we need something a bit more detailed / for newbies
>>>
>>>
>>> I am hoping that this is good enough for now:
>>>
>>> http://ddili.org/ders/d.en/ranges.html
>>
>> It sure is! This should be advertised somehow.
>
> Should I redditize?
>
> Andrei
>
If that question was for me, of course I wouldn't mind, at all. ;)
Ali
|
January 16, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 1/15/12, Jacob Carlborg <doob@me.com> wrote:
> I'm not completely sure how it works but it
> looks like that Fields mixin can be replace with the code you have
> referenced from my Orange library and opDispatch.
You mean your `fieldsOf` template? I'm not really sure how that would work, I've tried this:
This opBinary(string op)(This rhs)
{
This res;
foreach (field; fieldsOf!This)
{
mixin("res." ~ field ~ " = this." ~ field ~ op ~ " rhs." ~
field ~ ";");
}
return res;
}
But that gives me errors:
Error: variable __aggr901 cannot be read at compile time
Error: variable __aggr901 cannot be read at compile time
Error: variable __key902 cannot be read at compile time
Error: variable __aggr901 cannot be read at compile time
Error: variable __aggr901 cannot be read at compile time
Anyway that Fields mixin was something I wrote as a quick example for the book. I've also tried using traits(allMembers), but that didn't work too good.
|
January 16, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 2012-01-16 12:43, Andrej Mitrovic wrote: > On 1/15/12, Jacob Carlborg<doob@me.com> wrote: >> I'm not completely sure how it works but it >> looks like that Fields mixin can be replace with the code you have >> referenced from my Orange library and opDispatch. > > You mean your `fieldsOf` template? I'm not really sure how that would > work, I've tried this: > > This opBinary(string op)(This rhs) > { > This res; > foreach (field; fieldsOf!This) > { > mixin("res." ~ field ~ " = this." ~ field ~ op ~ " rhs." ~ > field ~ ";"); > } > > return res; > } > > But that gives me errors: > Error: variable __aggr901 cannot be read at compile time > Error: variable __aggr901 cannot be read at compile time > Error: variable __key902 cannot be read at compile time > Error: variable __aggr901 cannot be read at compile time > Error: variable __aggr901 cannot be read at compile time > > Anyway that Fields mixin was something I wrote as a quick example for > the book. I've also tried using traits(allMembers), but that didn't > work too good. This compiles and run as expected for me using dmd 2.057: http://pastebin.com/fq27831F But I was thinking if the Fields mixin is necessary at all. Since it's possible to get and set the values of structs and objects using tupleof. I was thinking it would be possible to use this technique directly in Notify. Something like this: struct Notify (T) { auto opBinary (string op, T) (T rhs) { T result; foreach (i, dummy ; T.tupleof) mixin("result.tupleof[i] = raw.tupleof[i] " ~ op ~ " rhs.tupleof[i];\n"); return result; } } -- /Jacob Carlborg |
January 16, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Ah, I completely forgot about tupleof. That could work. Originally I've tried __traits() but it didn't work. Thanks. |
January 16, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 2012-01-16 21:41, Andrej Mitrovic wrote: > Ah, I completely forgot about tupleof. That could work. Originally > I've tried __traits() but it didn't work. Thanks. No problem. Although tupleof works for private and protected fields as well. Don't know if that would be a problem. -- /Jacob Carlborg |
January 17, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound2@digitalmars.com> wrote in message news:jet0kk$1h97$1@digitalmars.com... > On 1/14/2012 1:00 PM, Nick Sabalausky wrote: >> "Walter Bright"<newshound2@digitalmars.com> wrote in message news:jesl4i$30v3$1@digitalmars.com... >>> >>> You and I are going to disagree on this. >>> >> >> Dosn't the reader mean "The reader and I are going to disagree on this"? >> ;) >> (only j/k, of course. Although I have always hated when authors say "the >> reader" instead of "you" which is what was obviously meant anyway. I just >> sounds bad. I always read it as a clear sign the author was trying *way* >> too >> hard to be "correct".) > > I agree with your comment about "the reader" being pretentious. > > As for my use of "you" there, I was talking specifically to Jonathan. That's different from writing a tech manual. Wearing jeans is appropriate in a conversation. > Yup, just kidding on that like I said. :) >>> But I will add that excessive use of "you" in technically minded books tends to, in my mind, reduce the book a grade in quality. >> >> The key there is "excessive use", not "any use". Eliminating excessive >> use >> of "you" certainly improves the quality. But compulsively eliminating >> "you", >> at best, makes the text sound pedantic, at worst, decreases the quality. >> Either way, compulsively eliminating it leads to pointless contrivances >> and >> awkward euphemisms like "the reader". > > The steps are: > > Novice: follow the rules because you're told to > > Master: follow the rules because you understand the rules > > Guru: break the rules because you know the limits of the rules Very, very true. |
January 17, 2012 Re: A tutorial on D templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | "dennis luehring" <dl.soluz@gmx.net> wrote in message news:jeu3mf$94o$1@digitalmars.com... >> https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf > > ...with acrobat reader... Eewww. Do youself a favor and grab a copy of FoxIt Reader. Works just as well, but isn't an insane resource hog. Adobe == bloatware. |
Copyright © 1999-2021 by the D Language Foundation