Fun with lists



Jaime,

I find the list_slice() function particularly useful. 
However, I wish that the existing "sublist" function, which 
has a name suggesting the same or similar functionality, 
could be extended to take arguments n, m and then do what 
your list_slice does.

I don't know if others think that's feasible, but I am in 
favor of reducing the number of names/terms as much as possible.

On the same subject, I find having both of the names 
"sublis"  and "sublist", with totally different 
functionality, confusing.

							Kostas

Jaime Villate wrote:
> Hi,
> these are very trivial list functions that can be very handy. Please
> comment on more appropriate names, better ways to do the same, other
> similar functions that you would like to see in a package of list
> utilities, etc.
> 
> Regards,
> Jaime
> 
> (%i1) list_slice(l,n,m):=if (n>0) then rest(rest(l,n+m-1-length(l)),n-1)
>   else rest(rest(l,m+n-1),length(l)+n)$
> 
> (%i2) list_remove(l,n,m):=if listp(l)
>   then append(rest(l,n-1-length(l)),rest(l,n+m-1))
>   else funmake(op(l),list_remove(args(l),n,m))$
> 
> (%i3) list_shuffle(l) := block([r], for n:length(l) step -1 thru 2
>  do (r:random(n), l:endcons(part(l,r+1),list_remove(l,r+1,1))), l)$
> 
> (%i4) list_slice([a,b,c,d,e], 2, 3);
> (%o4)                    [b, c, d]
> 
> (%i5) list_remove([a,b,c,d,e], 2, 3);
> (%o5)                      [a, e]
> 
> (%i6) list_shuffle([a,b,c,d,e]);
> (%o6)                 [a, c, d, e, b]
> 
> (%i9) list_shuffle(a.b.c.d.e);
> (%o9)                c . a . d . e . b
> 
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima