Skip to content

Instantly share code, notes, and snippets.

@nickknw
Created April 5, 2012 04:24
Show Gist options
  • Save nickknw/2307907 to your computer and use it in GitHub Desktop.
Save nickknw/2307907 to your computer and use it in GitHub Desktop.
Odd prolog syntax
% Following code sample from 'Higher Order Logic Programming In Prolog' by Lee Naish
% www.csee.umbc.edu/771/papers/mu_96_02.pdf
% insertion sort (simple version)
isort([], []).
isort(A.As, Bs) :-
isort(As, Bs1),
isort(A, Bs1, Bs).
% insert number into sorted list
insert(N, [], [N]).
insert(N, H.L, N.H.L) :-
N =< H.
insert(N, H.LO, H.L) :-
N > H,
insert(N, LO, L).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment