Created
July 7, 2017 20:53
-
-
Save deech/0ca48c30d1f12c186968e173fb8cefd2 to your computer and use it in GitHub Desktop.
D Compile Time TCO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
double factorial (double i) | |
{ | |
if (i == 1) { | |
return 1; | |
} | |
else { | |
return (i * factorial(i - 1)); | |
} | |
} | |
void main() | |
{ | |
pragma(msg, factorial(1000)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ dub build; ./factorial
Performing "debug" build using dmd for x86_64.
factorial ~master: building configuration "application"...
source/app.d(3,8): Error: function app.factorial CTFE recursion limit exceeded
source/app.d(9,26): called from here: factorial(i - 1.00000)
source/app.d(3,8): 1000 recursive calls to function factorial
source/app.d(15,24): called from here: factorial(1001.00)
source/app.d(15,3): while evaluating pragma(msg, factorial(1001.00))
dmd failed with exit code 1.