How can I write a predicate that takes a List like [1,2,3,4,5,6] and binds NewList to a list formed by interchanging pairs of members of the list, so in the example, NewList would be [2,1,4,3,6,5]. If the list has an odd number, then the final one is left unchanged at the end of the NewList.
Eg:
:spin([cat,dog,fish],X)?
X=[dog,cat,fish]
the english version:
If List is empty, SpunList is also empty.
If List is one element, SpunList is a list of that same element.
If List has two or more elements (in prolog, List = [A,B|Rest]),
SpunList is constructed by swapping A and B, then spinning the Rest.
Thanks.
Regards,
Yupar
Eg:
:spin([cat,dog,fish],X)?
X=[dog,cat,fish]
the english version:
If List is empty, SpunList is also empty.
If List is one element, SpunList is a list of that same element.
If List has two or more elements (in prolog, List = [A,B|Rest]),
SpunList is constructed by swapping A and B, then spinning the Rest.
Thanks.
Regards,
Yupar