The correct way to print a delimited collection in SmallTalk is Squeak?

I am trying to override the printOn method with this code:

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

      

where "coordinates" means the name of the collection (OrderedCollection), but I was expecting to print this when called in the Transcript show:

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

      

I got this instead:

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

      

I am. e quotes were also printed.

I tried to play with it by defining a local variable and using it, etc. Nothing succeeded.

+3


source to share


1 answer


Don't use #print:

to print strings. Use #nextPutAll:

for security (works for all collections). #print:

writes the string representation to the stream and surrounds the argument with quotes, so you end up with quotes in the output file.



+8


source







All Articles