lambda recursion
Ali Çehreli
acehreli at yahoo.com
Fri Nov 27 20:53:37 UTC 2020
On 11/27/20 9:01 AM, ddcovery wrote:
> On Friday, 27 November 2020 at 16:40:43 UTC, ddcovery wrote:
>> ...
>> * Can the lambda be transformed to a template (using T instead "int")
>> but avoiding function/return syntax?
>>
>> This is an example using function
>>
>> template qs(T){
>> T[] qs( T[] items ){
>> return items.length==0
>> ? items
>> : chain(
>> qs(items[1..$].filter!(i=> i<items[0] ).array),
>> items[0..1],
>> qs(items[1..$].filter!(i=> i >= items[0]).array)
>> ).array;
>> }
>> }
>
> I mean... transform this into a lambda expression:
>
> T[] qs(T)( T[] items ){
> return items.length==0
> ? items
> : chain(
> qs(items[1..$].filter!(i=> i<items[0] ).array),
> items[0..1],
> qs(items[1..$].filter!(i=> i >= items[0]).array)
> ).array;
> }
>
This has been done with the Y-combinator, where the lambda refers to
itself as 'self':
https://github.com/gecko0307/atrium/blob/master/dlib/functional/combinators.d
There has been been other discussions on it on these forums.
Ali
More information about the Digitalmars-d-learn
mailing list