different/2 - does a pure, determinate definition exist?

后端 未结 8 1028
野的像风
野的像风 2020-12-07 00:24
different(Xs, Ys) :-
   member(X, Xs),
   non_member(X, Ys).
different(Xs, Ys) :-
   member(Y, Ys),
   non_member(Y, Xs).

While this definition usi

8条回答
  •  抹茶落季
    2020-12-07 00:56

    (Much inspired by @repeat's last answer, the names are still too clumsy)

    different(Xs, Ys) :-
       if_(tnotexists_inlist_t(list_memberd_t(Ys), Xs),
          true,
          tnotexists_inlist_t(list_memberd_t(Xs), Ys)).
    
    tnotexists_inlist_t(_P_2, [], false).
    tnotexists_inlist_t(P_2, [E|Es], T) :-
       if_(call(P_2, E),
          tnotexists_inlist_t(P_2, Es, T),
          T = true).
    

提交回复
热议问题