On 7/10/07, Edward A. Romana <erom at earthlink.net> wrote:
>
> Is there a ready made Maxima function perform cyclic left or right shift
> of a list,
> for example:
>
> (%i1) L:[a,b,c,d]$
> (%i2) left_shift(L,2);
> (%o2) [c,d,a,b]
No, but it is easy enough to write:
left_rotate(l,n):=append(rest(l,n),rest(l,n-length(l)))$
This only works for 0<n<=len(n). To handle all integer n's, it's only a
little more complicated:
left_rotate(l,n):=block([len:length(l)],
n: if len=0 then 0 else mod(n,len),
append(rest(l,n),rest(l,n-length(l))));
-s