Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-30 Thread Andrej Mitrovic
On 1/30/11, Philippe Sigaud wrote: > 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. Is this going in the next release? There's an nary template in std.

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-30 Thread Philippe Sigaud
On Sun, Jan 30, 2011 at 12:03, Tom 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 > com

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-30 Thread Tom
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 do

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Jonathan M Davis
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 wo

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
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..

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
Well I've updated the tutorial anyway. I just left a note and used an templateImpl companion template.

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
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.

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
Wait, why won't this compile?: template foo(int value) { int result; alias result foo; } void main() { writeln( foo!(4) ); }

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
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).

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Trass3r
Save this somewhere or it will be lost here ;)

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
Fix: So essentially it allows us to use any string of characters instead of "b". I've meant "a" here, not "b".

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
Note when I said "But, we *did* pass a valid argument," I was refering to the original code example I gave at the top where we called unaryFun for the first time.

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
Woops, sorry about the missing function definition after the line: "unaryFun takes the string argument and might create this function:" This should be maybe: int unaryFun(int a) { return (a & 1) == 0; } But that's oversimplification since that instantiation is a function template itself, not

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
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. At first, I started using function templates, because they were the easiest to grasp. Or so I thought. Basically I just used function templates

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
P.S. Tom, I'm writing an explanation on how unaryFunImpl works right now, but it's long. Give me a few more minutes and it'll be done. :)

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Andrej Mitrovic
Andrei, I think there's a lurking bug in unaryFunImpl, on line 53: enum testAsExpression = "{ ElementType "~parmName ~"; return ("~fun~");}()"; enum testAsStmts = "{"~ElementType.stringof ~" "~parmName~"; "~fun~"}()"; Notice the second enum,

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread Tomek Sowiński
Tom napisał: > I am learning D for some time. I come from background of C, C# and Python. > When I saw the ways to use std.algorithem's functions, I have noticed that the > input lambda's can be writen as strings. Somewhat like the pythonic "exec". I > went to the source of this feature in functio

Re: How can you read and understand the source of *naryFun in functional.d?

2011-01-29 Thread bearophile
Tom: > The functions unaryFun and binaryFun. Is there a way I can read them and > understand them easily? or maybe I missed something? If you learn D well, you will be able to read them. But even if you know D they aren't easy to read. It's not easy stuff, that's standard-library-grade material