1
replaceEltByclass(E1:リスト、E2:リスト)を定義しようとしています。Eはサブリストのないリストです。クラスCに属するE1の各要素は、Cの 要素に置き換えられます。最終結果はE2に入れられます。たとえば、目標rep_class([e1、e4、e6、e11]、E2)はリストE2を提供します:[[e1、e8、e10]、e4、[e3、e6、e7]、e11]。私は良い結果がありません。リストの各要素を特定のリストに置き換えます
/*The code*/
/*facts*/
class(c1,[e3, e6, e7]).
class(c2,[e1, e8, e10]).
/*rules*/
rep_class([],[]).
rep_class([E|Q],E2) :-
class(C,L),
not(member(E,L)),
concat(E2,E,E2),
rep_class(Q,E2).
rep_class([E|Q],E2) :-
class(C,L),
member(E,L),
concat(E2,L,E2),
rep_class(Q,E2).
/*conventional concat*/
concat([],L,L).
concat([H|T],L,[H|Res]) :- concat(T,L,Res).
それは持っています正しい行動。私はまた、findall述語を使用する間違いと必要性を理解しています。 – Hana