Compile-time calculation: Difference between revisions

Content added Content deleted
(Merge omitted languages at bottom and add Processing)
(Added Prolog)
Line 1,001: Line 1,001:
0.0030411 Seconds
0.0030411 Seconds
3628800
3628800
</pre>

=={{header|Prolog}}==
For this, and many other complex calculations, goal_expansion/2 can be used.

goal_expansion/2 will change the goal in the code at compile time to be something else, in the case the constant number.
<lang Prolog>% Taken from RosettaCode Factorial page for Prolog
fact(X, 1) :- X<2.
fact(X, F) :- Y is X-1, fact(Y,Z), F is Z*X.
goal_expansion((X = factorial_of(N)), (X = F)) :- fact(N,F).
test :-
F = factorial_of(10),
format('!10 = ~p~n', F).</lang>
{{out}}
<pre>
?- test.
!10 = 3628800
true.

?- listing(test).
test :-
A=3628800,
format('!10 = ~p~n', A).
</pre>
</pre>