I have two questions I am working on and I'm simply having a hard time understanding the question. The first being:
Quote:
Create a Prolog predicate flatten_append/3
which has 3 arguments that are all lists. The third list should be equivalent to the concatenation of the flattened versions of the first list followed by the flattened version of the second list. For example, flatten append([1,2,[3,4,5],[6]],[[7],[8,[9]]],X)
should succeed binding X
to the list [1,2,3,4,5,6,7,8,9]
. Use the built-in predicates append/3
and flatten/2
.
Does creating a predicate mean I make a new file that I then consult to run? Also for three arguments is that like this
thing([], [X], X)
or would that only be one and I need something like this for three arguments?
thing([],[X],X).
thing([H|T],[H|X],Y) :- H = 1, anything(Y,Z), thing(T,X,Z).
thing([H|T],[H|X],Y) :- H = 0, nothing(Y,Z), thing(T,X,Z)
Finally what does it mean when it says succeed binding
X
? Is there a specific order or at the end you assign X equal to what you just made? Thanks
What I have tried:
suffix([Ys], Xs) :-
flatten([Ys], Xs).
prefix([Ys], Xs) :-
flatten([Ys], Xs).
flatten_append([Xs], [Ys], X) :-
suffix(Xs, Zs),
prefix(Zs, Ys).
But I need to append the flattened lists into one new list as
X
.
X
comes back as a singleton variable.