On 05/09/2015 05:52 PM, Dennis Ritchie wrote:
On Saturday, 9 May 2015 at 14:15:21 UTC, Ali Çehreli 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);
On Saturday, 9 May 2015 at 21:48:05 UTC, Timon Gehr wrote:
Well, it is much slower due to all the allocated closures, owed
to the fact that the implementations of 'fix' on that page are
expected to mirror a particular famous implementation in
untyped lambda calculus.
In case you have a use
On Saturday, 9 May 2015 at 11:20:10 UTC, Dennis Ritchie wrote:
Hi,
Can lambda functions or delegates in D to call themselves?
Can I write something like this:
-
import std.stdio;
void main() {
auto fact = function (int x) = x * { if (x) fact(x - 1); };
assert(fact(10) ==
Hi,
Can lambda functions or delegates in D to call themselves?
Can I write something like this:
-
import std.stdio;
void main() {
auto fact = function (int x) = x * { if (x) fact(x - 1); };
assert(fact(10) == 3628800);
}
Dennis Ritchie wrote:
auto fact = function (int x) = x * { if (x) fact(x - 1); };
int fact (int x) { return x * ( x1 ? fact(x - 1): 1); };
-manfred
On 05/09/2015 01:20 PM, Dennis Ritchie wrote:
Hi,
Can lambda functions or delegates in D to call themselves?
Can I write something like this:
-
import std.stdio;
void main() {
auto fact = function (int x) = x * { if (x) fact(x - 1); };
assert(fact(10) == 3628800);
}
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 :)
On Saturday, 9 May 2015 at 14:15:21 UTC, Ali Çehreli 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 :)
On Saturday, 9 May 2015 at 14:47:21 UTC, Russel Winder wrote:
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
On 05/09/2015 07:47 AM, Russel Winder via Digitalmars-d-learn wrote:
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.
I don't
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
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
On 05/09/2015 10:45 AM, Russel Winder via Digitalmars-d-learn wrote:
On Sat, 2015-05-09 at 09:49 -0700, Ali Çehreli via Digitalmars-d-learn wrote:
[…]
BigInt factorial(size_t n)
{
return bigInts(1).take(n).reduce!((a, b) = a *= b);
}
I wonder if that should be a * b rather than a *=
On Sat, 2015-05-09 at 09:49 -0700, Ali Çehreli via Digitalmars-d-learn wrote:
[…]
BigInt factorial(size_t n)
{
return bigInts(1).take(n).reduce!((a, b) = a *= b);
}
I wonder if that should be a * b rather than a *= b?
It turns out that 2.067 fixes the integrality of BigInts so:
14 matches
Mail list logo