users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: append 3 lists in the same time


From: Henk Vandecasteele
Subject: Re: append 3 lists in the same time
Date: Fri, 29 Mar 2002 15:31:02 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20011126 Netscape6/6.2.1

Hi,

define:

append_lists([], []).
append_lists([X|Y], Result):-
        ( Y = [] -> Result = X
        ;
          append_lists(Y, TempResult),
          append(X, TempResult, Result)
        ).

Then you can call:

  append_lists([A,B,C], L).

The first argument can have as many elements as wanted. They should all be lists of course.

more efficient version, different behaviour when the first argument
is free:

append_lists([], []).
append_lists([X|Y], Result):-
         append_lists2(Y, X, Result).

append_lists2([], X, X).
append_lists2([X|Y], Z, Result):-
        append_lists2(Y, X, TempResult),
        append(Z, TempResult, Result).

Henk


Gurvan Le Guernic wrote:

    Hi,
Is there a way to append more than 2 lists in the same time in
gnu-prolog.
Like the 'o' in other prolog.
Example:
instead of typing: append(A,B,L1), append(L1,C,L).
we could type something like: L=A o B o C.


_______________________________________________
Users-prolog mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/users-prolog






reply via email to

[Prev in Thread] Current Thread [Next in Thread]