Thank Pelle , and others.
I'm thinking ways to do this task :
http://rosettacode.org/wiki/Anonymous_recursion
With this last version of Y-combinator
http://rosettacode.org/wiki/Y_combinator#D ,
it look like this:
ulong fib(long n) {
if(n < 0) throw new Exception("No negative") ;
return Y((ulong delegate(ulong) self) {
return (ulong m) {
return (m <= 1) ? m : self(m-1) + self(m-2) ;
} ;
})(n) ;
}
and works. Only that this Y-combinator seems induced a lot of
overhead(four return statements in the Y's definition).
From D document, if i not misunderstood, a delegate has 2 property .ptr
(frame pointer) and .funcptr (address of function), so the delegate
should be a structure? Would there be a hack to get access to this
structure? It seems not now.
Thanks again.
Pelle wrote: