Let’s say a variable number of lists has been given, 5 for example, but one can enter any number of lists: [1,2] + [3,4,5] + [6,7,8,9] + [10,11] + [12,13,14] equals L. should give the following list inside the variable L: [1,2,3,4,5,6,7,8,9,10,11,12,13,14].
Here’s my code for the concatenation of two lists:
joinLists([FLH|FLT], SL, [FLH|RLT]):-
joinLists(FLT, SL, RLT).
joinLists([], H, H).
:-op(500, xfx, +).
:-op(600, yfx, equals).
X + Y equals Z:-
joinLists(X, Y, Z).
[1,2,3] + [4,5,6,7] equals L. gives L = [1,2,3,4,5,6,7], but how to solve the problem for an indefinite number of lists?
I think your operators declaration is incorrect, the sum should be associative (i also change the symbols, just to fit my aesthetic preference, and to avoid changing the behaviour of standard +/2):
then you can write
test
I don’t see any convenience in such definition, consider that SWI-Prolog append/2 source is available…