Lambda functions in D

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 9 07:47:08 PDT 2015


On Sat, 2015-05-09 at 07:15 -0700, Ali Çehreli via Digitalmars-d-learn wrote:
> On 05/09/2015 04:59 AM, Dennis Ritchie wrote:
> > On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote:
> > > assert((function int(int
> > > x)=>x?x*__traits(parent,{})(x-1):1)(10)==3628800);
> > 
> > Thanks. Yes, it is similar to what I wanted :)
> 
> Also interesting:
> 
>    http://rosettacode.org/wiki/Y_combinator#D
> 
> I think that code was improved by Timon Gehr as well.
> 
> Ali

Sadly all the solutions are unsound since they are recursive but not
tail recursive. Oh it doesn't matter as D doesn't have tail call
optimization.

There are lots of good imperative implementations.

Of course none of the implementation can calculate factorial(24) as
they are using hardware values which are bounded and cannot store
reasonable numbers.

Could use iota. Oh no we can't as BigNums are not integral.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150509/90b4c9b4/attachment-0001.sig>


More information about the Digitalmars-d-learn mailing list