Smalltalk Matrix 零错误

Smalltalk Matrix nil error

所以我 运行 这个代码在 pharos 6.0 的操场上,它给了我一个错误,说“unindex object is not accessable。基本上,我正在尝试制作一个 8x10 的矩阵。如何做我做一个?

  | aMatrix row col|


  aMatrix := Matrix new.
  aMatrix numberOfColumns: 3.
  aMatrix numberOfRows: 3. 
  aMatrix at: 2 at: 2 put: 6.

如果你想制作一个 8x10 的矩阵,你为什么要这样做

aMatrix numberOfColumns: 3.
aMatrix numberOfRows: 3. 

?

我检查了代码,但我不明白为什么要这样实现。 numberOfColumns:numberOfRows:只是将参数赋值给一个实例变量,并没有改变内部数据结构。

你应该这样做:

aMatrix := Matrix rows: 8 columns: 10.   
aMatrix at: 2 at: 2 put: 6.