首页 > 解决方案 > SWISH Prolog 阶乘误差

问题描述

fact(0,1).
fact(N,F):-
    (   
        N>0:-
        (   N1 is N-1,
            fact(N1,f1),
            F is N*F1
        )
    ;   
    write("N less than 0 nor allowed")
    ).

在本教程中,作者的代码正在运行。我编写了相同的代码,但我的代码不起作用。他正在用 cgwin(即离线)写作,而我正在用 SWISH(即在线)写作。

查询已通过:fact(3,R).
错误消息:

Singleton variables: [R]
Singleton variables: [F1]
procedure `(A:-B)' does not exist
Reachable from:
      fact(A,B)

标签: prologfactorial

解决方案


推荐阅读