Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The right way to print a collection with delimiter in SmallTalk - Squeak?

I have been trying to redefine the printOn method by using this code:

coordinates do: [:elem | aStream print: elem] separatedBy: [aStream print: ' ,']

where "coordinates" stands for the name of the collection (OrderedCollection), but i was expecting to print this when calling to Transcript show:

(2/2) ,(1/1) ,(3/3) ,(-4/4)

I got this instead:

(2/2)','(1/1)','(3/3)','(-4/4)

i. e the quotes was printed as well.

I have tried to play with it, defining a local variable and use it, etc. Nothing worked.

like image 811
wannabe programmer Avatar asked Dec 09 '25 07:12

wannabe programmer


1 Answers

Don't use #print: to print strings. Use #nextPutAll: to be safe (works for all collections). #print: writes a string representation on the stream and surrounds the argument with quotes, that's why you get quotes in the output.

like image 93
Max Leske Avatar answered Dec 13 '25 02:12

Max Leske



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!