Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Prolog
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:

Prolog
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.
Posted
Updated 29-Apr-20 7:09am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900