'Consult with variables an predicate PROLOG

the thing is that if for example i ask ?- maxC([1,2,3,4], K, M). it have to return:

K=0 M = [];
K=1 M = [1];
K=2 M = [1,2];
K=3 M = [1,2,3];
K=4 M =[1,2,3,4];
false.

But it doesn´t

maxC(_,0,[]). %->return empty when 0
maxC([H|_], 1,[H]).%-> return the last element
maxC([],_,[]). %-> return empty if list of entrance is empty
maxC([H|T],Nesimo,[H|T2]):- I is Nesimo - 1, maxC(T,I,T2),!.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source