I have the following utility predicate and was a little bit surprised that I was leaving a choice point behind, so I inserted the cut in the first clause. I thought that indexing of the list would lead to this cut being unnecessary, but it appears that is not the case. Is this because it is not the first argument, or a metapredicate?
/*
* mapm(P:predicate,L:list,O:list,S0:any,SN:any) is nondet.
*
* Monadic map over state
*/
:- meta_predicate mapm(4,?,?,?,?).
mapm(_P,[],[],S,S) :-
!.
mapm(P,[H|T],[HP|TP],S0,SN) :-
call(P,H,HP,S0,S1),
mapm(P,T,TP,S1,SN).