Anonymous user
Anonymous recursion: Difference between revisions
Added simple D entry
m (→{{header|REXX}}: added comments, added subroutine fence, added DO-END comment label, changed comments, added whitespace. -- ~~~~) |
(Added simple D entry) |
||
Line 331:
=={{header|D}}==
<lang d>uint fib(in uint n) pure nothrow {
In D anonymous delegates/functions can't refer themselves. Here an anonymous class is created, and by using opCall member function, the anonymous class object can take arguments and act like an anonymous function. The recursion is done by calling opCall inside itself.▼
immutable self = &__traits(parent, {});
return (n < 2) ? n : self(n - 1) + self(n - 2);
}
void main() {
import std.stdio;
writeln(fib(39));
}</lang>
{{out}}▼
<pre>63245986</pre>▼
===With Anonymous Class===
▲In
<lang d>import std.stdio;
Line 350 ⟶ 362:
writeln(fib(39));
}</lang>
The output is the same.
▲{{out}}
▲<pre>63245986</pre>
=={{header|Dylan}}==
|