简体   繁体   English

分隔序言中的事实列表

[英]Separating list of facts in prolog

I have a list of facts in Prolog.我在 Prolog 中有一个事实列表。 Say:说:

L = [mother(sue), father(sam), mother(rachel), mother(izzie), father(leo)] 

I want to separate them into two lists我想将它们分成两个列表

L1 = [mother(sue), mother(rachel), mother(izzie)]
L2 = [father(sam), father(leo)]

How do I do that in Prolog我如何在 Prolog 中做到这一点

I hope I'm not doing your homework for you, but here it is:我希望我不是在为你做作业,但它是:

split([], [], []).
split([mother(X)|L], [mother(X)|L1], L2) :- split(L, L1, L2).
split([father(X)|L], L1, [father(X)|L2]) :- split(L, L1, L2).

Usage:用法:

?- split([mother(sue), father(sam), mother(rachel), mother(izzie), father(leo)], L1, L2).
L1 = [mother(sue), mother(rachel), mother(izzie)],
L2 = [father(sam), father(leo)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM