i have followed this previuos thread How to manage 2d array in Smalltalk? but it did not helped me please help me out .
I am trying to create NXN array and then print them out . for exmaple 2x2 array : what am i missing ?
|testArr|.
testArr := (Array new: 2)
at: 1 put: ((Array new: 2) at: 1 put: '0'; at: 2 put: 'X');
at: 2 put: ((Array new: 2) at: 1 put: 'P'; at: 2 put: 'Y').
1 to:2 do:[:a|
1 to:2 do:[:b|
Transcript show: testArr at:a at:b.
].
].
THE ERROR IS AT Transcript with unknow selector . what can i do to fix it ?
There are several issues with your code:
First the error message you describe. I guess in full length it says:
MessageNotUnderstood: ThreadSafeTranscript>>show:at:at:
So this means you should set some parenthesis to get the right messages to the right objects. Try:
Transcript show: ((testArr at:a) at:b).
Now there is an issue with your Array assignments too.
In Smalltalk/Pharo/Squeak, if you send at:put:
to an array it returns the object you assigned, the second parameter of at:put:
, not the receiver. So in your example the variable testArr
doesn't contain an array of arrays, but the string 'Y'.
If you really want to use message cascading with ;
, you must send the yourself
message to the array at the end of your cascade.
Like this:
testArr := (Array new: 2).
testArr at: 1 put: ((Array new: 2) at: 1 put: '0'; at: 2 put: 'X'; yourself).
testArr at: 2 put: ((Array new: 2) at: 1 put: 'P'; at: 2 put: 'Y'; yourself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With