Lists

Write a predicate
prefixes(L,M)
that, given a list L = [X1, X2, ... , Xn],
calculates a list M of all of the prefixes of
L: [[X1,..., Xn], [X1, ... , Xn−1], ... , [X1, X2], [X1], [ ]]

Example

?-  prefixes([],M).   M = [[]].   
?-  prefixes([1,2],M) M = [[1,2],[1],[]]
?-  prefixes([1,1,1],M).   M = [[1,1,1],[1,1],[1],[]]
```

This is not a site where we do your homework for you. If have a specific problem related to SWI-Prolog we can help. :slightly_smiling_face:

Please see: Minimal and reproducible working examples

This is easy if you can just use findall and reverse:

prefixes_in_reverse_order(L, M) :-
    is_list(L),
    findall(P, append(P, _, L), Ps),
    reverse(Ps, M).

But do you somehow have to interleave the list building and the splitting?