Prolog 中的三个依赖参数



我是prolog的新手。所以请任何人指导我正确的方式!我有两个参数 CctypeInt 和 Ru1下面的关系说:如果

CctypeInt 为 0,则 Ru1 是一个列表 {2,3,4},如果 CctypeInt 是 1,Ru1 是一个列表 {2,3,4},CctypeInt 是 2 Ru1 是一个列表,其中包含一个元素{2}
relation(CctypeInt,[0-{2,3,4}, 1-{2,3,4}, 2-{2}],Ru1),

这里的一切都很好。但是还有第三个参数可以采用如下解释的值:

(
CctypeInt is 0 then Ru2 is -1
    ;CctypeInt is 1 and Ru1 is  2 then Ru2 is [2,3,4]
    ;CctypeInt is 1 and Ru1  is  3 then Ru2 is [2,3]
    ;CctypeInt is 1 and Ru1  is  4 then Ru2 is 2
    ;CctypeInt is 2 then Ru1 is 2 then Ru2 is 2
    ),!.

我尝试了以下代码。

        (
CctypeInt=:=0->Ru2 is -1
    ;CctypeInt=:=1,Ru1 =:= 2->Ru2 is [2,3,4]
    ;CctypeInt=:=1,Ru1 =:= 3->Ru2 is [2,3]
    ;CctypeInt=:=1,Ru1 =:= 4->Ru2 is 2
    ;CctypeInt=:=2->Ru1 is 2,Ru2 is 2
    ),!.

但是我收到一个错误,例如CctypeInt 的范围为 0..2,无法比较。

也许我错过了一些东西,但这似乎可以完成这项工作:

% relation(CctypeInt, Ru1, Ru2)
relation(1,2,[2,3,4]).
relation(1,3,[2,3]).
relation(1,4,2).
relation(2,2,2).

最新更新