[Pharo-project] cull: protocol

Randal L. Schwartz merlyn at stonehenge.com
Fri Feb 19 08:14:41 EST 2010

>>>>> "Levente" == Levente Uzonyi <leves at elte.hu> writes:

Levente> Here is a working example (the linked version has a bug):
Levente> BlockClosure >> cull: argument1 cull: argument2

Levente>  	numArgs = 2 ifTrue: [ ^self value: argument1 value: argument2 ].
Levente>  	numArgs = 1 ifTrue: [ ^self value: argument1 ].
Levente>  	^self value

The error message here will be misleading if it's a 3 arg block,
saying that it wants 3 args, but was given 0, when in fact you *offered*
two args.

Perhaps the tests could be done in the reverse order:

    numargs = 0 ifTrue: [^self value].
    numargs = 1 ifTrue: [^self value: argument1].
    ^self value: argument1 value: argument2.

Then, you'll get a sensible message... "offered 2, wanted 3"

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

More information about the Pharo-dev mailing list