[Cuis] String concatenation with non-strings

David Graham dgraham at unthinkable.org
Fri Dec 6 11:16:13 CST 2013


Hi All,
I occasionally run into this issue when porting code and was curious if 
there is a specific reason why the String>>, method doesn't send an 
"asString" message to any non-String objects being concatenated?

For example, if I open a workspace and do a print-it on the following:
'test: ', 5
It errors and the debugger shows that the message ends up being handled 
by Sequenceable collection which fails.

Here is the Cuis code from String>>,:
, aStringOrText
     ^ (aStringOrText is: #Text)
         ifTrue: [ self asText , aStringOrText ]
         ifFalse: [ super , aStringOrText ].

Squeak:
, anObject
     "Concatenate the argument to the receiver.
         Transcript cr; show: 'The value is: ', 3.
     "
     ^ self copyReplaceFrom: self size + 1
           to: self size
           with: anObject asString

Regards,
David




More information about the Cuis mailing list