[squeak-dev] The Inbox: Kernel-cmm.814.mcz

Levente Uzonyi leves at elte.hu
Fri Oct 25 20:21:04 UTC 2013


On Fri, 25 Oct 2013, Chris Muller wrote:

> You might be right about #valueWithEnoughArguments: being the same as
> #valueWithPossibleArgs.
>
> But, as you can see from the comment, valueWithAllPossibleArguments:
> was written with awareness of the existence of
> #valueWithPossibleArgs:, so I would not intentionally add a redundant
> method.
>
> What I need here is a single evaluation method which allows me to pass
> EITHER a fixed number of arguments, or an unknown, variable number of
> arguments.
>
> If the receiver Block takes 0 args, OR 2+ args, it operates exactly as
> valueWithPossibleArgs:.
>
> The receiver block takes 1 argument, and anArray specifies precisely
> one argument, it operates exactly as valueWithPossibleArgs:.
>
> If, however, he receiver block takes 1 argument, and anArray specifies
> _multiple_ arguments, then those arguments are passed into the block
> as an Array.

Why is this needed? Isn't it better to just wrap your argument array in 
another array, instead of introducing a new method with a rather unusal 
behavior?


Levente

>
> On Fri, Oct 25, 2013 at 3:05 PM, Levente Uzonyi <leves at elte.hu> wrote:
>> We already have two methods for this: #valueWithEnoughArguments: and
>> #valueWitPossibleArgs:. I think we should keep the first, and deprecate the
>> second.
>>
>>
>> Levente
>>
>>
>> On Fri, 25 Oct 2013, commits at source.squeak.org wrote:
>>
>>> A new version of Kernel was added to project The Inbox:
>>> http://source.squeak.org/inbox/Kernel-cmm.814.mcz
>>>
>>> ==================== Summary ====================
>>>
>>> Name: Kernel-cmm.814
>>> Author: cmm
>>> Time: 25 October 2013, 2:27:37.722 pm
>>> UUID: c757a2a8-26b1-422b-8b8b-4bf6640efbb4
>>> Ancestors: Kernel-cmm.813
>>>
>>> Added BlockClosure>>#valueWithAllPossibleArguments: to support passing a
>>> variable number of arguments to the image from the command-line.
>>>
>>> =============== Diff against Kernel-cmm.813 ===============
>>>
>>> Item was changed:
>>> + ----- Method: BlockClosure>>valueOtherwise: (in category 'evaluating')
>>> -----
>>> - ----- Method: BlockClosure>>valueOtherwise: (in category
>>> 'events-support') -----
>>>  valueOtherwise: aBlock
>>>         "Send the message and answer the return value"
>>>
>>>         ^self value!
>>>
>>> Item was added:
>>> + ----- Method: BlockClosure>>valueWithAllPossibleArguments: (in category
>>> 'evaluating') -----
>>> + valueWithAllPossibleArguments: anArray
>>> +       "Same as valueWithPossibleArgs: except when the receiver takes
>>> just one-argument, and more than one argument is specified by anArray, then
>>> pass all of anArray as THE argument to the receiver block
>>> +       This is used to allow a large, variable number of arguments to be
>>> passed."
>>> +       ^numArgs = 0
>>> +               ifTrue: [self value]
>>> +               ifFalse:
>>> +                       [self valueWithArguments:
>>> +                               (numArgs = anArray size
>>> +                                       ifTrue: [anArray]
>>> +                                       ifFalse:
>>> +                                               [numArgs > anArray size
>>> +                                                       ifTrue: [anArray,
>>> (Array new: numArgs - anArray size)]
>>> +                                                       ifFalse:
>>> +                                                               [numArgs =
>>> 1
>>> +
>>> ifTrue: [Array with: anArray]
>>> +
>>> ifFalse: [anArray copyFrom: 1 to: numArgs]]])]!
>>>
>>> Item was changed:
>>> + ----- Method: BlockClosure>>valueWithArguments:otherwise: (in category
>>> 'evaluating') -----
>>> - ----- Method: BlockClosure>>valueWithArguments:otherwise: (in category
>>> 'events-support') -----
>>>  valueWithArguments: anArray otherwise: aBlock
>>>
>>>         ^ self valueWithArguments: anArray!
>>>
>>> Item was changed:
>>> + ----- Method: BlockClosure>>valueWithEnoughArguments: (in category
>>> 'evaluating') -----
>>> - ----- Method: BlockClosure>>valueWithEnoughArguments: (in category
>>> 'events-support') -----
>>>  valueWithEnoughArguments: anArray
>>>         "call me with enough arguments from anArray"
>>>         | args |
>>>         (anArray size == self numArgs)
>>>                 ifTrue: [ ^self valueWithArguments: anArray ].
>>>
>>>         args := Array new: self numArgs.
>>>         args replaceFrom: 1
>>>                 to: (anArray size min: args size)
>>>                 with: anArray
>>>                 startingAt: 1.
>>>
>>>         ^ self valueWithArguments: args!
>>>
>>>
>>>
>>
>
>


More information about the Squeak-dev mailing list