prolog中的三个相关参数
我对prolog完全是新手。所以请任何人指导我该走的正确道路! 我有两个参数CctypeInt和Ru1 下面的关系表示: 如果CctypeInt为0,则Ru1为列表{2,3,4};如果CctypeInt为1,则Ru1为列表{2,3,4},且CctypeInt为2,则Ru1为具有一个元素{2}的列表prolog中的三个相关参数,prolog,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 i
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).
那么,
CctypeInt
是一个范围吗?你试过打印它吗?是的,它是一个范围…使用这个范围,我正确地提取了Ru1的范围,但是因为Ru2依赖于cctypeint和Ru1,所以我有写逻辑的问题。