Showing posts with label Prolog. Show all posts
Showing posts with label Prolog. Show all posts

Wednesday, March 30, 2011

Shift list elements in Prolog

An interesting way how to make the shift to the left and right of list elements, without any special complexity. lshift and rshift predicates:
lshift([H|L], S) :- append(L, [H], S).
rshift(L, S) :- lshift(S, L).
And append predicate:
append([], L, L).
append([H|X], Y, [H|Z]) :- append(X, Y, Z).