[squeak-dev] The Trunk: CollectionsTests-cmm.206.mcz

Chris Muller asqueaker at gmail.com
Wed Sep 4 15:16:04 UTC 2013


The latter.  Just as with other "as" methods, if it is already in the
desired state, answer it "as"-is.  :)

I have not yet committed it but here is the new implementation of #asMutator:

asMutator
     "Return a setter message from a getter message. For example,
#name asMutator returns #name:"
     ^ self last = $:
          ifTrue: [ self ]
          ifFalse: [ (self copyWith: $:) asSymbol ]

The comment indicates the purpose is for converting a getter to a
setter, and since a method selector cannot be empty, sending asMutator
to an empty Symbol should raise an error.

On Wed, Sep 4, 2013 at 10:02 AM, Levente Uzonyi <leves at elte.hu> wrote:
> On Sat, 31 Aug 2013, commits at source.squeak.org wrote:
>
>> Chris Muller uploaded a new version of CollectionsTests to project The
>> Trunk:
>> http://source.squeak.org/trunk/CollectionsTests-cmm.206.mcz
>>
>> ==================== Summary ====================
>>
>> Name: CollectionsTests-cmm.206
>> Author: cmm
>> Time: 31 August 2013, 4:34:41.685 pm
>> UUID: 18d460d5-be23-418b-a3f0-b340b0c3e948
>> Ancestors: CollectionsTests-nice.205
>>
>> testAsMutator test with a selector that already ends with a colon.
>
>
> The previous "contract" was that the user was responsible for sending the
> #asMutator message to the right receiver. Let's say that "contract" is
> wrong. How would you fix #asMutator?
>
> Would you raise an error if the receiver is not an accessor? E.g.:
>
>         self numArgs
>                 caseOf: {
>                         [ 0 ] -> [ ^(self copyWith: $:) asSymbol ] }
>                         [ 1 ] -> [ self isKeyword ifTrue: [ ^self ] ].
>                 otherwise: [ ].
>         self error: 'Receiver is not an accessor.'
>
> Or just try to add a colon to the end if it's not there? E.g.:
>
>         (self size > 0 and: [ (self at: self size) == $: ]) ifTrue: [ ^self
> ].
>         ^(self copyWith: $:) asSymbol
>
>
> Levente
>
>
>>
>> =============== Diff against CollectionsTests-nice.205 ===============
>>
>> Item was changed:
>>  ----- Method: SymbolTest>>testAsMutator (in category 'tests') -----
>>  testAsMutator
>> +       self
>> +               assert: #x asMutator = #x: ;
>> +               assert: #x: asMutator = #x: ;
>> +               assert: #x asMutator isSymbol!
>> -
>> -       self assert: #x asMutator = #x:.
>> -       self assert: #x asMutator isSymbol!
>>
>>
>>
>


More information about the Squeak-dev mailing list