【问题标题】:Adding two params of a predicate that aren't static添加两个非静态的谓词参数
【发布时间】:2013-04-08 06:13:54
【问题描述】:

我正在尝试将两个数字相加

add(num1, num2, output) :-
    output is num1 + num2.

假设 X 为 1,Y 为 3,但它们不是静态的,只是变量。
add(X, Y, out)

我收到 error(instantiation_error,(is)/2) 错误

有什么建议吗?

【问题讨论】:

    标签: math prolog arithmetic-expressions


    【解决方案1】:

    Prolog 是一种区分大小写的语言,变量名必须是由字母、数字和下划线字符组成的字符序列,并且必须以大写字母或下划线字符开头

    因此,
    add(Num1, Num2, Output) :- Output is Num1 + Num2.
    会工作的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      相关资源
      最近更新 更多