Fun with lists



I have been using the R system lately for a variety of analyses, and
it builds a lot of functionality into subscripting.

In particular, subscripting by a list of positive integers selects
those positions.  Subscripting by a list of negative integers selects
all *except* those positions.  Subscripting by a list of booleans
selects the corresponding positions; if the subscript list is shorter
than the subscripted list, it is "recycled". Subscripting by the
missing-data symbol (NA) returns an NA.

In general, Maxima objects can be subscripted by arbitrary objects, so
x[[2,3]] is a perfectly correct expression, though Maxima assigns no
meaning to it.  On the other hand, Maxima does not allow concrete
lists (as opposed to variables) to be subscripted by anything but
integers: [5,6][i] => error; [5,6][[2,3]] => error.  So it would be
possible to allow R-style subscripting semantics for Maxima, e.g.

    [a,b,c][[1,3]] => [a,c]
    [a,b,c][[-1,-2]] => [c]
    [a,b,c][[TRUE, FALSE, TRUE]] => [a,c]

This could also be extended to matrices or lists-of-lists, e.g.

    m : matrix([a,b,c],[d,e,f],[g,h,i])
    m[[1,3],[2,1]] => matrix([b,a],[h,g])

In R syntax, a missing subscript indicates all values, e.g. m[1,]; we
would need some different convention for that, e.g. m[1,ALL]:

    m[ALL,[2,1]] == m[[1,2,3],[2,1]] => matrix( [b,a], [e,d], [h,g] )

R allows these operators on the left-hand side of assignments.

Other important features:

* R also supports multidimensional arrays as objects (as opposed to
Maxima's hasharrays and other non-object arrays), which would be nice
to have.  I suppose this could be done using lists-of-lists-of-lists
in the natural extension of the current Matrix system, or in a number
of other ways.
* R supports labelling both rows and columns, and selection of rows
and columns by name.

Well, enough for now.  Discussion?

        -s