Skip to content

Instantly share code, notes, and snippets.

@deech
Created July 7, 2017 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deech/0ca48c30d1f12c186968e173fb8cefd2 to your computer and use it in GitHub Desktop.
Save deech/0ca48c30d1f12c186968e173fb8cefd2 to your computer and use it in GitHub Desktop.
D Compile Time TCO
import std.stdio;
double factorial (double i)
{
if (i == 1) {
return 1;
}
else {
return (i * factorial(i - 1));
}
}
void main()
{
pragma(msg, factorial(1000));
}
@deech
Copy link
Author

deech commented Jul 7, 2017

$ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment