Posted by
jas on
Nov 11, 2004; 2:22am
URL: https://forum.world.st/Character-asCharacter-tp3372010p3372053.html
Blair McGlashan wrote:
> "Chris Uppal" <
[hidden email]> wrote in message
> news:
[hidden email]...
>
>>Is there any reason why there's no Character>>asCharacter method even
>>though
>>there is an Integer>>asCharacter ?
>>
>>An oversight, or would it be ideologically unsound ?
>
>
> The latter. Integer>>asCharacter is unsound, and not just ideologically;
> there is an infinite range of Integer's for which the conversion does not
> make sense, and of course Integers and characters are only equivalent if one
> thinks in 'C', they certainly don't meet the criteria of supporting
> compatible protocols. So we would rather not have included
> Integer>>asCharacter either, but as I recall it was in Smalltalk-80 so we
> added it for the sake of compatibility.
>
> Regards
>
> Blair
[| a b |
a := aString collect: [:each| each asInteger asCharacter].
b := aString collect: [:each| each asCharacter].
a = b ifTrue: ['makes sense']
ifFalse: ['makes no sense']
] on: Error do: [:ex| ^#cipherString:]
==
a := #() asOrderedCollection.
b := a asArray.
a add: #supportCommonProtocols.
b add: #supportCommonProtocols.
==
a := #().
b := OrderedCollection new.
c := a asOrderedCollection.
d := b asOrderedCollection.
c add: #supportCommonProtocols.
d add: #supportCommonProtocols.
a inspect.
b inspect.
==
It would take some work to actually make this consistent.
I understand Kent's argument that asThing should only be
implemented when receiver and thing supportCommonProtocols,
but I'm not sure the result is all that valuable, even to
pedantic. I could just as easily be convinced that saying
asThing is just shorthand for (Thing from: self printString),
and is sufficiently motivated by convenience. After which
I would be happy to discover that while asThing will short-
circuit wherever it can, asThingCopy will *always* return
a new object, and that everyone always implements both.
`Course I also do this:
Object>>asString
^self displayString
so I'm already non-standard. ;-)
Regards,
-cstb