[Pharo-project] Method expressed as symbol, used as argument
It was pointed out that given an instance method MyClass >> doSomething that MyClass do: [:each | each doSomething]. can be expressed as MyClass do: #doSomething. 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-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
You probably talk about something like : Assuming an instance method called #doSomething the following are identical: myInstance doSomething myInstance perform: #doSomething ----------------- Benoit St-Jean Yahoo! Messenger: bstjean A standpoint is an intellectual horizon of radius zero. (Albert Einstein) ________________________________ From: DougEdmunds <dougedmunds@gmail.com> To: pharo-project@lists.gforge.inria.fr Sent: Fri, March 18, 2011 9:40:43 PM Subject: [Pharo-project] Method expressed as symbol, used as argument It was pointed out that given an instance method MyClass >> doSomething that MyClass do: [:each | each doSomething]. can be expressed as MyClass do: #doSomething. 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-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
DougEdmunds 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.
Can someone suggest something to read that explains the usage of # here (#doSomething), the relation of methods to symbols, etc.
Message selectors (in your example âdoSomethingâ) are represented by Symbols. You might use it to parameterize the behavior of an object. For example you can pass a message selector to a PluggableButtonMorph to tell it, which message to perform, when the button is pressed. -- View this message in context: http://forum.world.st/Method-expressed-as-symbol-used-as-argument-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
On Sat, Mar 19, 2011 at 2:40 AM, DougEdmunds <dougedmunds@gmail.com> 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-td3... 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-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
I'd read up on Higher Order Messaging as to me this is an application of it. Googling for it should give you some good results, one of the hits will most likely be a paper co-authored by Stephane which was presented at OOPSLA 2005 if I'm not mistaken. Cheers Carlo On 19 Mar 2011, at 3:40 AM, DougEdmunds 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. 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-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
And you can put it as an specific application of High order programming (high order functions, high order predicates...). I can suggest you to learn Haskell too <3 :D Guille On Sat, Mar 19, 2011 at 5:11 PM, Carlo <snoobabk@yahoo.ie> wrote:
I'd read up on Higher Order Messaging as to me this is an application of it. Googling for it should give you some good results, one of the hits will most likely be a paper co-authored by Stephane which was presented at OOPSLA 2005 if I'm not mistaken.
Cheers Carlo
On 19 Mar 2011, at 3:40 AM, DougEdmunds 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.
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-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Hi carlo here this is something quite simple based on the fact that a symbol can understand value: and perform the method. This is simple and we can use it for what it does. Stef On Mar 19, 2011, at 9:11 PM, Carlo wrote:
I'd read up on Higher Order Messaging as to me this is an application of it. Googling for it should give you some good results, one of the hits will most likely be a paper co-authored by Stephane which was presented at OOPSLA 2005 if I'm not mistaken.
Cheers Carlo
On 19 Mar 2011, at 3:40 AM, DougEdmunds 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.
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-tp3388864p... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
participants (7)
-
Benoit St-Jean -
Carlo -
DougEdmunds -
Guillermo Polito -
Helene Bilbo -
Mariano Martinez Peck -
Stéphane Ducasse