Skip to content

Instantly share code, notes, and snippets.

@stesh
Created September 29, 2011 17:18
Show Gist options
  • Save stesh/1251313 to your computer and use it in GitHub Desktop.
Save stesh/1251313 to your computer and use it in GitHub Desktop.
contains(X, [X | _]).
contains(X, [_ | T]) :- contains(X, T).
equals([], []).
equals([_|T1], [_|T2]) :- equals(T1, T2).
len([], 0).
len([_|T], L) :- len(T, L1), succ(L1, L).
empty([]).
first([H|_], H).
last([_,L], L).
last([_|T], L) :- last(T, L).
unshift(X, L, L1) :- L1 = [X|L].
push(X, [], [X]).
push(X, [H|T], [H|Y]) :- push(X, T, Y).
pop([X], []).
pop([H|T], [H|T1]) :- pop(T, T1).
at([X], 0, X).
at([H|T], Y, Z) :- at(T, Y1, Z), succ(Y, Y1).
zip([], [], []).
zip([H|T], [H1|T1], X) :- X = [H,H1|Y], zip(T, T1, Y).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment