squeak - How to Create 2D arrays in smalltalk -


i have followed previuos thread how manage 2d array in smalltalk? did not helped me please me out .

i trying create nxn array , print them out . exmaple 2x2 array : 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 @ transcript unknow selector . can fix ?

there several issues code:

first error message describe. guess in full length says:

messagenotunderstood: threadsafetranscript>>show:at:at:

so means should set parenthesis right messages right objects. try:

transcript show: ((testarr at:a) at:b). 

now there issue array assignments too.

in smalltalk/pharo/squeak, if send at:put: array returns object assigned, second parameter of at:put:, not receiver. in example variable testarr doesn't contain array of arrays, string 'y'.

if want use message cascading ;, must send yourself message array @ end of 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). 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -