January 29, 2011 Re: How can you read and understand the source of *naryFun infunctional.d? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Akakima | On 1/29/11, Akakima <akakima33@gmail.com> wrote: > > "Andrej Mitrovic" <andrej.mitrovich@gmail.com> > >>I hope this gets pasted right, otherwise I'll have to open a freakin' blog. >> >>:) >> >> Up until a few months ago, I had no experience with templates whatsoever. >> > > That's very good stuff! Well written and very helpful. > > May i suggest you to put that somewhere in a [ maybe new ] section of digitalmars site reserved to other documentation like that. > > As a newbee, i can tell you that this would help. > > Thanks > Thanks. Well, I'm not the maintainer of the D website. Maybe I could put it up on wiki4d (http://prowiki.org/wiki4d/wiki.cgi?FrontPage). Someone will have to direct the newbies there. |
January 29, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Save this somewhere or it will be lost here ;) |
January 29, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Done: http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/D2Templates I've replaced my obvious English mistakes with slightly less obvious ones. Kinda wish prowiki had a nicer code display though (syntax highlighting would be nice). |
January 29, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Wait, why won't this compile?: template foo(int value) { int result; alias result foo; } void main() { writeln( foo!(4) ); } |
January 29, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Oh yeah, it's that damn bug where you can't have multiple declarations, otherwise aliases don't work. I still don't know if that bug will ever be fixed or if I should add that to the tutorial. |
January 29, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Well I've updated the tutorial anyway. I just left a note and used an templateImpl companion template. |
January 30, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Well now I'm feeling really stupid because apparently this is how it *should* work, at least according to the docs. I'd love to see 'alias symbol this' work even with multiple declarations. It'd be nicee.. |
January 30, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
On Saturday 29 January 2011 16:01:06 Andrej Mitrovic wrote:
> Well now I'm feeling really stupid because apparently this is how it *should* work, at least according to the docs.
>
> I'd love to see 'alias symbol this' work even with multiple declarations. It'd be nicee..
It's how it should work according to TDPL. It'll get fixed It's just a question of when.
- Jonathan M Davis
|
January 30, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | I would like to thank you for that such a great explanation of the Template-based programming in that unary example. I think it's great you have uploaded that to the wiki4d, and it's definite will help a lot of people that come from other common languages background (like C, C# and Python) that don't support full templating, to understand that design pattern. And with that close tracking to the functional.d code, I thing but not sure that we've found some bugs. I will do some testing later today, and if I will see what I think to be wrong, I'll update. and again, Thanks |
January 30, 2011 Re: How can you read and understand the source of *naryFun in functional.d? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom | On Sun, Jan 30, 2011 at 12:03, Tom <tom@gmail.com> wrote: > I would like to thank you for that such a great explanation of the Template-based > programming in that unary example. I think it's great you have uploaded that to > the wiki4d, and it's definite will help a lot of people that come from other > common languages background (like C, C# and Python) that don't support full > templating, to understand that design pattern. > And with that close tracking to the functional.d code, I thing but not sure that > we've found some bugs. I will do some testing later today, and if I will see what > I think to be wrong, I'll update. If anyone is interested, I coded a n-args version of unaryFun/binaryFun called naryFun. If you use 'a', 'b', ... as args names, it can automatically determine the templated function arity. So naryFun!"a + b * c - sin(d-a)" is a 4-args template function. It's there: http://svn.dsource.org/projects/dranges/trunk/dranges/docs/functional.html (look for naryFun at the bottom) code is here: http://dsource.org/projects/dranges/browser/trunk/dranges/functional.d It could be simpler now: when I did it 18 months ago, CTFE wasn't so powerful. The looping templates can now easily be done with a simple foreach. This has been on my todo list for quite some time... Philippe |
Copyright © 1999-2021 by the D Language Foundation