views:

218

answers:

1

I need a relation in prolog to shift list left rotationally by one element such that ?shift([1,2,3],L) should produce L=[2,3,1]. could you help me?

+2  A: 

You can use the append command to combine elements of a list together:

shift([H|T], Y) :-
  append(T, [H], Y).

So you simply append the tail and head together (in that order), and set Y to that newly-created list. Note that since H is an element and not a list, you must surround it with [ and ] to make it a list in the append function.

Also, here's a good basic overview of using lists in Prolog.

Kaleb Brasee