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 |
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 <[hidden email]> To: [hidden email] 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-tp3388864p3388864.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com. |
In reply to this post by DougEdmunds
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. |
In reply to this post by DougEdmunds
On Sat, Mar 19, 2011 at 2:40 AM, DougEdmunds <[hidden email]> wrote: It was pointed out that given an instance method 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
|
In reply to this post by DougEdmunds
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-tp3388864p3388864.html 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 <[hidden email]> wrote: I'd read up on Higher Order Messaging as to me this is an application of it. |
In reply to this post by carlo.t
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-tp3388864p3388864.html > Sent from the Pharo Smalltalk mailing list archive at Nabble.com. > > > |
Free forum by Nabble | Edit this page |