lambda recursion

2020-11-27 Thread ddcovery via Digitalmars-d-learn
I want to express in D the known Haskell qsort 3 lines code (it is not a quick sort, but an example of how functional programming is expressive). This is the "javascript" version I use as reference: const sorted = ( [pivot, …others] ) => pivot===void 0 ? [ ] : [ … sorted( others.fi

Re: lambda recursion

2020-11-27 Thread ddcovery via Digitalmars-d-learn
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

Re: lambda recursion

2020-11-27 Thread Ali Çehreli via Digitalmars-d-learn
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 ){  

Re: lambda recursion

2020-11-28 Thread ddcovery via Digitalmars-d-learn
On Friday, 27 November 2020 at 20:53:37 UTC, Ali Çehreli wrote: 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. A