Most general higher-order constraint describing a sequence of integers ordered with respect to a relation

Hoogle was not very useful, but Hayoo is! foldcmpl so this is a special form of fold for a list, but it does not apply length list times but one time less. isSortedBy is not entirely general in its name, but in its signature. Maybe insisting on the most general name is not that helpful. … Read more

Definition of Reflexive Transitive Closure

It’s useful, but in my opinion not yet ideal because I cannot cut duplicate paths at the point of their creation. Consider, with the complete graph K_n: n_complete(N, Es) :- numlist(1, N, Ns), phrase(pairs(Ns), Es). adjacent(Edges, X, Y) :- member(edge(X, Y), Edges). pairs([]) –> []. pairs([N|Ns]) –> edges(Ns, N), pairs(Ns). edges([], _) –> []. edges([N|Ns], … Read more

Prolog map procedure that applies predicate to list elements

This is usually called maplist/3 and is part of the Prolog prologue. Note the different argument order! :- meta_predicate(maplist(2, ?, ?)). maplist(_C_2, [], []). maplist( C_2, [X|Xs], [Y|Ys]) :- call(C_2, X, Y), maplist( C_2, Xs, Ys). The different argument order permits you to easily nest several maplist-goals. ?- maplist(maplist(test),[[1,2],[3,4]],Rss). Rss = [[1,4],[9,16]]. maplist comes in … Read more