I have this list of lists:
L = [[[a,b],[d,e]],[[m,f],[p,o]],[[r,l],[v,d]]].
I want to write a function using Prolog that flattens it in a way that it becomes like this :
L = [[a,b],[c,d],[m,f],[p,o],[r,l],[v,d]].
Any suggestions? Thank you.
Using the predicate
append/2
:You should look at the implementation by SWI-Prolog and copy it if you need to. Leave out the
must_be/2
if you must do it in GNU-Prolog.But if you need this because of
findall/3
, keep in mind that there might also be afindall/4
available (not for GNU-Prolog, but SWI-Prolog has it):Almost every situation where you need to flatten a list could be avoided using difference lists.