Skip to content
Prev 34761 / 63421 Next

Negative integer subscripts in [[?

On 09/11/2009 4:38 PM, William Dunlap wrote:
I agree, it would be better not to allow negatives here, but as John 
said it's probably too late to do away with them.
I don't follow this.  Recursive lists are trees, and you specify a 
single element of a tree by specifying a sequence of indices.  Why would 
it be less confusing to give a list?  What extra flexibility could there 
be?  I suppose you could mix integer and character indices, but what 
would be meant by x[[ list(1, list(2,3), 4) ]] ?

I don't know the original motivation for allowing vector indexing to 
lists, but I extended it to pairlists so that it would be possible to 
specify a location within a function exactly, by walking down the parse 
tree.  I think it's something that would be rarely used, but when you 
need it, it's very handy.

Duncan Murdoch