argument of ifNotNil: must be a 0-argument block
Mathieu
mathk.sue at gmail.com
Sat Sep 2 00:02:38 UTC 2006
Ken Causey a écrit :
> As Andreas points out this is because this apparent method call is
> actually compiled by the compiler. (And the error is actually from the
> compiler, not a result of sending the message.) Perhaps incorrectly
> depending on your point of view. I would recommend using 'ifNotNilDo:'
> instead when you want the offending object.
>
> Ken
Yes but it is less faster beceause old compiler don't optimize the message.
>
> On Sat, 2006-09-02 at 00:25 +0100, Zulq Alam wrote:
>> Hi List,
>>
>> Why does "Object new ifNotNil: [:object | ]" result in the syntax error
>> "argument of ifNotNil: must be a 0-argument block" when the code appears
>> to be fine with this?
>>
>>
>> ProtoObject>>ifNotNil: ifNotNilBlock
>> "Evaluate the block, unless I'm == nil (q.v.)"
>>
>> ^ ifNotNilBlock valueWithPossibleArgs: {self}
>>
>>
>> BlockClosure>>valueWithPossibleArgs: anArray
>>
>> | n |
>> (n := self numArgs) = 0 ifTrue: [^ self value].
>> n = anArray size ifTrue: [^ self valueWithArguments: anArray].
>> ^ self valueWithArguments: (n > anArray size
>> ifTrue: [anArray, (Array new: n - anArray size)]
>> ifFalse: [anArray copyFrom: 1 to: n]): anArray
>>
>>
>>
>> A quick search of Mantis for ifNotNil or valueWithPossibleArgs hasn't
>> left me any wiser. Something to do with the interpreter, perhaps
>> optimisation?
>>
>> Thanks,
>> Zulq.
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>>
More information about the Squeak-dev
mailing list
|