On Sat, Mar 19, 2011 at 2:40 AM, DougEdmunds <[email protected]> wrote:

> It was pointed out that given an instance method
>   MyClass >> doSomething
> that
>   MyClass do: [:each | each doSomething].
> can be expressed as
>   MyClass do: #doSomething.
>


The reasons is this: check the #do:   implementation and you will see all it
does is to send #value:.
But who says that only BlockClosure cna understand #value:   ?
Indeed, Symbol  DOES UNDERSTAND value:  ;)  and it is:

Symbol >> value: anObject
    ^anObject perform: self.

So.....a selector is a Symbol....

Check this thread:

http://forum.world.st/OffTopoc-Symbol-understands-value-nice-hehehehehhe-td3020595.html

Now...whether it is cool to use it or not, it is another question. FOr
iterating collections I would always use the normal approach.

cheers

Mariano


> Can someone suggest something to read that explains the usage of #
> here (#doSomething), the relation of methods to symbols, etc.
>
> Trying to wrap my head around it. Thanks.
>
> -dae
>
>
>
> --
> View this message in context:
> http://forum.world.st/Method-expressed-as-symbol-used-as-argument-tp3388864p3388864.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>
>

Reply via email to