% Factorial in prolog % This one remembers its values, ready for the next call... :-dynamic(f/2). f(1,1):-!. f(N,_):-N=<0,!,fail. f(N,F):-N1 is N-1, f(N1,F1), F is F1 * N, print(N),write('!='), print(F), nl, Fact=.. [ :-, f(N,F),! ], asserta(Fact).