Your problem is not very well defined. Are empty sequences allowed or not? Shall [#]
be related to [[],[]]
(there is an empty sequence before and after) or []
? You say it should be []
. So:
list_splitbyhash(Xs, Xss) :-
phrase(splitby(Xss,#), Xs).
splitby([],_E) -->
[].
splitby(Xss,E) -->
[E],
splitby(Xss,E).
splitby([Xs|Xss],E) -->
{Xs = [_|_]},
all_seq(dif(E),Xs),
splitby(Xss,E).
all_seq(_, []) --> [].
all_seq(C_1, [C|Cs]) -->
[C],
{call(C_1,C)},
all_seq(C_1, Cs).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…