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:52:01 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20011126 Netscape6/6.2.1

hi,

remark that:

> o( A, o( B, C)) :- append(A, B, X), o(X, C).
> o( X, X) :- X \= o(_, _).


has not linear complexity,
it will traverse the list A as many times as there are list to be
appended.

Regards,

Henk


Lindsey Spratt wrote:

On Fri, Mar 29, 2002 4:36 AM, Gurvan Le Guernic <mailto:address@hidden>
wrote:

instead of typing: append(A,B,L1), append(L1,C,L).
we could type something like: L=A o B o C.



Here is one approach.

If you'd be willing to type: A o B o C o L, where L is the "result" list,
then this can be implemented in standard prolog using an operator.

A possible implementation:

:- op( 900, xfy, o).

o( A, o( B, C)) :- append(A, B, X), o(X, C).
o( X, X) :- X \= o(_, _).

Examples:
'A o B o L.' -> 'append( A, B, L).'
'A o B o C o L.' -> 'append(A, B, X), append(X, C, L).'

-lindsey




_______________________________________________
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]