Re: How To: Passing curried functions around

2015-09-12 Thread Bahman Movaqar via Digitalmars-d-learn
On Friday, 11 September 2015 at 21:06:32 UTC, Ali Çehreli wrote: On 09/11/2015 02:04 PM, Ali Çehreli wrote: The same keyword has a different use with templates: And the official documentation: http://dlang.org/template.html#TemplateAliasParameter Thanks again!

Re: How To: Passing curried functions around

2015-09-11 Thread Ali Çehreli via Digitalmars-d-learn
On 09/11/2015 02:04 PM, Ali Çehreli wrote: The same keyword has a different use with templates: And the official documentation: http://dlang.org/template.html#TemplateAliasParameter Ali

Re: How To: Passing curried functions around

2015-09-11 Thread Ali Çehreli via Digitalmars-d-learn
On 09/11/2015 01:07 PM, Bahman Movaqar wrote: > On Friday, 11 September 2015 at 18:39:15 UTC, Ali Çehreli wrote: >> >> import std.stdio; >> >> >> >> bool isEven(int n) { >> >> return !(n % 2); >> >> } >> >> >> >> int readValidInt(alias validator)(string prompt) { >> >> readValidInt() is a func

Re: How To: Passing curried functions around

2015-09-11 Thread Bahman Movaqar via Digitalmars-d-learn
On Friday, 11 September 2015 at 18:39:15 UTC, Ali Çehreli wrote: >> import std.stdio; >> >> bool isEven(int n) { >> return !(n % 2); >> } >> >> int readValidInt(alias validator)(string prompt) { readValidInt() is a function template that takes two information: 1) The validator as its alia

Re: How To: Passing curried functions around

2015-09-11 Thread Ali Çehreli via Digitalmars-d-learn
On 09/11/2015 02:41 AM, Bahman Movaqar wrote: > On Friday, 11 September 2015 at 06:14:18 UTC, Ali Çehreli wrote: >> partial takes the function arguments as 'value template parameters'. >> Unfortunately, a function pointer like &isEven cannot be 'value >> template parameters'; only fundamental type

Re: How To: Passing curried functions around

2015-09-11 Thread Bahman Movaqar via Digitalmars-d-learn
On Friday, 11 September 2015 at 06:14:18 UTC, Ali Çehreli wrote: On 09/06/2015 12:05 PM, Bahman Movaqar wrote: > alias bool function(int n) validator_t; There is the relatively newer alias syntax which is more intuitive: alias Validator = bool function(int n); Great. This is easily re

Re: How To: Passing curried functions around

2015-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 09/06/2015 12:05 PM, Bahman Movaqar wrote: > alias bool function(int n) validator_t; There is the relatively newer alias syntax which is more intuitive: alias Validator = bool function(int n); > bool isEven(int n) { ... } > bool isPrime(int n) { ... } > /** > * keep

Re: How To: Passing curried functions around

2015-09-07 Thread Bahman Movaqar via Digitalmars-d-learn
On Monday, 7 September 2015 at 03:55:01 UTC, Meta wrote: The name validator_t is not idiomatic in D. Something like ValidatorFun should be preferred. Same for intReader_t; ReadIntFun is probably preferred, or even IntReader (but that would imply that it's a struct/class in my mind). Noted. Th

Re: How To: Passing curried functions around

2015-09-06 Thread Meta via Digitalmars-d-learn
The name validator_t is not idiomatic in D. Something like ValidatorFun should be preferred. Same for intReader_t; ReadIntFun is probably preferred, or even IntReader (but that would imply that it's a struct/class in my mind). As for the actual use of partial, it's perfectly fine and idiomati

Re: How To: Passing curried functions around

2015-09-06 Thread welkam via Digitalmars-d-learn
Now its clearer to me. You want delegates http://wiki.dlang.org/Function_literals

Re: How To: Passing curried functions around

2015-09-06 Thread Bahman Movaqar via Digitalmars-d-learn
On Sunday, 6 September 2015 at 19:22:41 UTC, welkam wrote: I dont know much about functional programming, but what stops you defining int readInt(string prompt, validator_t validator) { ... } as a free standing function and just call it from both parts of your code? What is the benefit of ind

Re: How To: Passing curried functions around

2015-09-06 Thread welkam via Digitalmars-d-learn
I dont know much about functional programming, but what stops you defining int readInt(string prompt, validator_t validator) { ... } as a free standing function and just call it from both parts of your code? What is the benefit of indirection that you create when passing function pointer?

How To: Passing curried functions around

2015-09-06 Thread Bahman Movaqar via Digitalmars-d-learn
I'm just learning D, so please bear with me if I'm asking something naive. Consider the following code skeleton: // in part A of the application... // - alias bool function(int n) validator_t; bool isEven(int n) { ...