On 17.08.2011 22:29, Philippe Marschall wrote:
On 17.08.2011 22:17, Stéphane Ducasse wrote:
I wrote
cull: anArg
"Execute the receiver with one or zero argument.
[ 1 + 2 ] cull: 5
returns 3
[ :x | 1+ 2 + x] cull: 5
returns 8
"
^numArgs = 0
ifTrue: [self value]
ifFalse: [self value: anArg]
So it's like #valueWithPossibleArgument:?
Almost.
cull: raises error if given blocks with too many args,
valueWithPossibleArgument(s): evaluates with the extra args as nil.
Why do we need two methods
that do the same thing?
Because valueWithPossibleArguments was there first, and we can't simply
remove it.
cull is more natural to use in 99.9% of the cases.
Also, #cull: protocol only goes up to 4 arguments, mirroring #value:
(#cullWithArguments: not being present is mostly an oversight though... )
Cheers,
Henry