How do I append 3 lists efficiently in Prolog?

前端 未结 3 1980
一向
一向 2021-01-13 22:43

I know how to do it for 2 lists:

append([],L,L).
append([H|T],L,[H|R]):-append(T,L,R).

but how to do it for 3? Without using the append for

3条回答
  •  半阙折子戏
    2021-01-13 22:59

    Hope I understood the question (and I don't think the following is more efficient than the other solutions here), but did you mean something like this?

    append([],[],L,L).
    append([],[H|T],L,[H|R]) :- append([],T,L,R).
    append([H|T],L0,L1,[H|R]) :- append(T,L0,L1,R).
    

提交回复
热议问题