How to create 2D arrays in smalltalk

I followed this preview How to manage a 2d array in Smalltalk? but it didn’t help me, please help me.

I am trying to create an NXN array and then print them. 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.
].
].

ERROR IN THE NETWORK WITH a fuzzy selector. what can i do to fix this?

+4
source share
1 answer

There are several problems in the code:

First reported error message. I assume in full it says:

MessageNotUnderstood: ThreadSafeTranscript -> show: at: at:

So this means that you have to set some brackets to get the right messages in the right objects. Try:

Transcript show: ((testArr at:a) at:b).

Now there is a problem with your array assignments.

Smalltalk/Pharo/Squeak, at:put: , , , at:put:, . , testArr , "Y".

;, yourself .

:

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).
+6

All Articles