I'm new to Prolog and I'm trying to get my head around lists. The problem I'm struggling with is: Given numbers in the form of lists (1 : [x], 3: [x, x, x]), implement the 'times' predicate /3. E.g.: times([x, x], [x, x, x], R). R = [x, x, x, x, x, x].
The plus, and successor predicates where 2 previous points of the exercise. I know I'm not using the successor predicate, but it didn't seem that useful later on.
This is what i've tried so far
successor([], [x]).
successor([X|T], R) :-
append([X|T], [X], R).
plus(L1, L2, R) :- append(L1, L2, R).
times([], _, []).
times(_, [], []).
times([_], L, L).
times(L, [_], L).
times([_|T], L2, R) :- plus(L2, R, RN),
times(T, L2, RN).
The output is: R is [].
append([X|T], [X], R)? - Willem Van Onsem