Relation in Prolog to offset elements left rotationally

I need an attitude in the prolog to shift the list on the left by one element so that

?shift([1,2,3],L) 

should produce

 L=[2,3,1]. 

Could you help me?

+4
source share
1 answer

You can use the append command to combine list items together:

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

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

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

+6
source

All Articles