Fun with lists



On 3/27/09, Stavros Macrakis <macrakis at alum.mit.edu> wrote:

> 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.

I've used R a lot and it's a great package in many ways.
I created the amatrix package which is now in share/contrib and
implemented R-style indexing.
A list of positive integers or list of booleans is recognized as
an index, although a list of negative integers is not.
I didn't try to implement the "recycling" bit.
The symbol 'all means all elements in a row or column.
NA is not recognized as an index.

Among other things, amatrix is an attempt to create a more
time & memory efficient matrix object. Elements are stored in a
1-d Lisp array. Indexing operations which yield contiguous rows
or columns return an object which shares storage with the original;
a copy-on-write scheme is implemented although I suspect it
has bugs.

demo(amatrix) shows some examples.

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

That's implemented for amatrix also.

I didn't try to implement any of these subscripting operations for
the existing list, matrix, or array types.

best

Robert Dodier