Re: Passing function as values and returning functions

2012-04-12 Thread Steven Schveighoffer
On Thu, 12 Apr 2012 10:49:03 -0400, James Miller wrote: Glad you got help Xan, but for future reference can you please keep questions to D.learn? It is somewhat frustrating to see the question "How do I do that?" on this list, since it is for discussion, and high-level questions, not for people

Re: Passing function as values and returning functions

2012-04-12 Thread James Miller
* James Miller [2012-04-13 02:49:03 +1200]: > Glad you got help Xan, but for future reference can you please keep > questions to D.learn? It is somewhat frustrating to see the question > "How do I do that?" on this list, since it is for discussion, and > high-level questions, not for people that

Re: Passing function as values and returning functions

2012-04-12 Thread James Miller
* Xan [2012-04-11 20:28:38 +0200]: > On Wednesday, 11 April 2012 at 13:04:01 UTC, Steven Schveighoffer > wrote: > >On Wed, 11 Apr 2012 08:53:00 -0400, Xan > >wrote: > > [snip] > >writeln(g(&f)(1)); > > > >Unlike C, you *must* take the address of a function symbol to get > >a function pointer. >

Re: Passing function as values and returning functions

2012-04-11 Thread Xan
On Wednesday, 11 April 2012 at 13:04:01 UTC, Steven Schveighoffer wrote: On Wed, 11 Apr 2012 08:53:00 -0400, Xan wrote: Thanks, Steve, but another problem: [snip] void main() { |___writeln(g(f)(1)); } writeln(g(&f)(1)); Unlike C, you *must* take the address of a function symbol to g

Re: Passing function as values and returning functions

2012-04-11 Thread Steven Schveighoffer
On Wed, 11 Apr 2012 08:53:00 -0400, Xan wrote: Thanks, Steve, but another problem: [snip] void main() { |___writeln(g(f)(1)); } writeln(g(&f)(1)); Unlike C, you *must* take the address of a function symbol to get a function pointer. -Steve

Re: Passing function as values and returning functions

2012-04-11 Thread Xan
On Wednesday, 11 April 2012 at 12:19:06 UTC, Steven Schveighoffer wrote: On Wed, 11 Apr 2012 08:08:44 -0400, Xan wrote: On Wednesday, 11 April 2012 at 11:59:14 UTC, Jacob Carlborg wrote: Use "delegate" or "function" both for the argument type and return type. How to do that? int funct

Re: Passing function as values and returning functions

2012-04-11 Thread Steven Schveighoffer
On Wed, 11 Apr 2012 08:08:44 -0400, Xan wrote: On Wednesday, 11 April 2012 at 11:59:14 UTC, Jacob Carlborg wrote: Use "delegate" or "function" both for the argument type and return type. How to do that? int function(int) g(int function(int a) p) { return p; } Should do the trick. dele

Re: Passing function as values and returning functions

2012-04-11 Thread Xan
On Wednesday, 11 April 2012 at 11:59:14 UTC, Jacob Carlborg wrote: On 2012-04-11 13:10, Xan wrote: Hi, Following the thread of Higher-order functions, how can I do to pass a function as a parameter and return a function. That is a something like: import std.functional, std.stdio; int f (in

Re: Passing function as values and returning functions

2012-04-11 Thread Jacob Carlborg
On 2012-04-11 13:10, Xan wrote: Hi, Following the thread of Higher-order functions, how can I do to pass a function as a parameter and return a function. That is a something like: import std.functional, std.stdio; int f (int a) { return 2*a; } int delegate (int) g(int function(int a) p) { ret

Passing function as values and returning functions

2012-04-11 Thread Xan
Hi, Following the thread of Higher-order functions, how can I do to pass a function as a parameter and return a function. That is a something like: import std.functional, std.stdio; int f (int a) { return 2*a; } int delegate (int) g(int function(int a) p) { return p; } void main() {