String concatenation with non-strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
dsg
Reply | Threaded
Open this post in threaded view
|

String concatenation with non-strings

dsg
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

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: String concatenation with non-strings

Juan Vuletich-4
Hi David,

This was never discussed... I think that going too far in that direction
could make Cuis look like Perl. Is there a god reason to do it?

Cheers,
Juan Vuletich

On 12/6/2013 2:16 PM, David Graham wrote:

> 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
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
dsg
Reply | Threaded
Open this post in threaded view
|

Re: String concatenation with non-strings

dsg
Thanks Juan.  No need to change, it was more of a philosophical
curiosity.  I noticed the bluebook had a similar example (pg 533), and
sent printString to the number before concatenating.

On 12/8/13 11:36 AM, Juan Vuletich wrote:

> Hi David,
>
> This was never discussed... I think that going too far in that
> direction could make Cuis look like Perl. Is there a god reason to do it?
>
> Cheers,
> Juan Vuletich
>
> On 12/6/2013 2:16 PM, David Graham wrote:
>> 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
>>
>> _______________________________________________
>> Cuis mailing list
>> [hidden email]
>> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>>
>


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org