argument of ifNotNil: must be a 0-argument block
Ken Causey
ken at kencausey.com
Fri Sep 1 23:46:12 UTC 2006
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
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.
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060901/5364f87e/attachment.pgp
More information about the Squeak-dev
mailing list
|