www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - function with is own lamda expression

reply "bioinfornatics" <bioinfornatics fedoraproject.org> writes:
I write a function with Lambda expression + safe + pure wich do 
same (close) as countUntil

http://www.dpaste.dzfl.pl/63d03540

but i fail to use lambda expression into my function. I try by 
two way
- alias this pred … (to get a default lambda)
- function(…) pred

both way i fail, could you take a look to code please.

Goal is to get a pure and safe function

thanks
Nov 30 2013
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 11/30/2013 05:53 PM, bioinfornatics wrote:

 I write a function with Lambda expression + safe + pure wich do same
 (close) as countUntil

 http://www.dpaste.dzfl.pl/63d03540

 but i fail to use lambda expression into my function. I try by two way
 - alias this pred … (to get a default lambda)
 - function(…) pred

 both way i fail, could you take a look to code please.

 Goal is to get a pure and safe function

 thanks
The obvious problem in the code is the fact that although the intent and the lambda expression itself is written to take two parameters, the lambda is called without any arguments: 1) The default lambda takes two parameters: auto search( alias pred = (a,b) => a == b, R,T,S=T)( const ref R toSearch, in T toMatch ) pure 2) and the provided lambda takes two parameters: assert( arrStruct.search!( (a,b) => a.id == b )( 8uL ) == 7 ); 3) However, the call itself takes no arguments: if( pred() ){ So, I would start with that call to debug and pass the two arguments that are appropriate (toSearch.front and toMatch, perhaps?) Ali
Dec 01 2013
parent "bioinfornatics" <bioinfornatics fedoraproject.org> writes:
On Sunday, 1 December 2013 at 08:22:41 UTC, Ali Çehreli wrote:
 On 11/30/2013 05:53 PM, bioinfornatics wrote:

 I write a function with Lambda expression + safe + pure wich
do same
 (close) as countUntil

 http://www.dpaste.dzfl.pl/63d03540

 but i fail to use lambda expression into my function. I try
by two way
 - alias this pred … (to get a default lambda)
 - function(…) pred

 both way i fail, could you take a look to code please.

 Goal is to get a pure and safe function

 thanks
The obvious problem in the code is the fact that although the intent and the lambda expression itself is written to take two parameters, the lambda is called without any arguments: 1) The default lambda takes two parameters: auto search( alias pred = (a,b) => a == b, R,T,S=T)( const ref R toSearch, in T toMatch ) pure 2) and the provided lambda takes two parameters: assert( arrStruct.search!( (a,b) => a.id == b )( 8uL ) == 7 ); 3) However, the call itself takes no arguments: if( pred() ){ So, I would start with that call to debug and pass the two arguments that are appropriate (toSearch.front and toMatch, perhaps?) Ali
Thanks Ali, that works now, i was close. http://www.dpaste.dzfl.pl/63d03540
Dec 01 2013