3

私はこの機能を使用します:

f(V):-V is [1,2,3,4,5].

しかし、私はエラーが発生します:

ERROR: '.'/2: Type error: `[]' expected, found `[2,3,4,5]' ("x" must hold one character)

何を修正する必要がありますか?

4

2 に答える 2

5

is/2 infix operator is used to evaluate arithmetic expressions.

It seems that you want to unify variable V with a term which is not an arithmetic expression (in this case a list), so you should use the equal operator (=).

f(V):- V = [1,2,3,4,5].

or alternatively unify directly in the head of the procedure:

f([1,2,3,4,5]).
于 2012-11-09T16:22:46.363 に答える
0

あなたのコードは、 f/1 が少数の数値セットを列挙する必要があることを示していると思います。これが本当なら、代わりに書くべきです

f(V) :- member(V, [1,2,3,4,5]).

次に、X を呼び出すf(X)と、リストされた値が (バックトラックで) バインドされます。

于 2012-11-09T16:36:58.000 に答える