Broken(?) Array2D behavior

Marc Santoro msantoro at pobox.com
Sun Mar 16 07:32:05 UTC 2003


Hello,

I have encountered weird behavior that I think is due to a bug.

This code:
foo _ Array2D width: 5 height: 20.
foo rowAndColumnValuesDo: [ :row :col :val ].

Will lead to a subscript out of range error. Note that using rowsAndColumnsDo 
doesn't lead to this error because it doesn't actually access the values.

Upon further investigation, I noticed that the indexX:y: method for Array2D 
appears incorrect. In Squeak 3.2, it appears thus:

indexX: x y: y
	(x < 1 or: [x > width]) ifTrue: [self errorSubscriptBounds: x].
	^ y - 1 * width + x

However, as normally invoked, x is the row, and y is the column, and 
essentially that is returning the index as column - 1 * width + row; based on 
the accessors, I think what is meant is this:

indexX: x y: y
	(y < 1 or: [y > width]) ifTrue: [self errorSubscriptBounds: y].
	^ (x - 1) * width + y

This revision appears to work correctly.

Thanks,
Marc.



More information about the Squeak-dev mailing list