I want to write a Wikipedia article about "Jacketing" and I thought a cool squeak snippet would show both how cool I am and how jacketing works. Unfortunately, the snippet is growing. I wanted to write it neatly short, like this (no callback:)
unblock: selector "Macht den blockierenden Aufruf selector unblockierend." |bs| bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird umbenannt" self addSelector: bs withMethod: (self methodAt: selector). self addSelector: selector withMethod: (self class compile: '[self perform: selector withArgs:args] fork') but as you probably noticed already, withArgs:args is not quite possible this way. Is there a short line of code that deals with it? niko -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer |
(1 to: thisContext method numArgs) collect: [ :each | thisContext tempAt: each ]
I'm sure there's a better way. Philippe 2006/7/18, Niko Schwarz <[hidden email]>: > I want to write a Wikipedia article about "Jacketing" and I thought a cool squeak snippet would show both how cool I am and how jacketing works. Unfortunately, the snippet is growing. I wanted to write it neatly short, like this (no callback:) > > unblock: selector > "Macht den blockierenden Aufruf selector unblockierend." > |bs| > bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird umbenannt" > > self > addSelector: bs > withMethod: (self methodAt: selector). > self addSelector: selector > withMethod: (self class compile: '[self perform: selector withArgs:args] fork') > > > but as you probably noticed already, withArgs:args is not quite possible this way. Is there a short line of code that deals with it? > > niko > -- > > > Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! > Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer > > |
In reply to this post by Niko Schwarz
Am 18.07.2006 um 15:12 schrieb Niko Schwarz: > I want to write a Wikipedia article about "Jacketing" and I thought > a cool squeak snippet would show both how cool I am and how > jacketing works. Unfortunately, the snippet is growing. I wanted to > write it neatly short, like this (no callback:) > > unblock: selector > "Macht den blockierenden Aufruf selector unblockierend." > |bs| > bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird > umbenannt" > > self > addSelector: bs > withMethod: (self methodAt: selector). > self addSelector: selector > withMethod: (self class compile: '[self perform: selector > withArgs:args] fork') > > > but as you probably noticed already, withArgs:args is not quite > possible this way. Is there a short line of code that deals with it? Untested, but might work: unblock: selector "Macht den blockierenden Aufruf selector unblockierend." |bs| bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird umbenannt" self addSelector: bs withMethod: (self methodAt: selector). self addSelector: selector withMethod: (self class compile: (self standardMethodHeaderFor: bs), '[self ', (self standardMethodHeaderFor: selector), '] fork') You do not need to perform if you are compiling anyway. Note that that you need to construct 'bs' differently if selector is an operator. - Bert - |
Am 18.07.2006 um 16:11 schrieb Bert Freudenberg: > > Am 18.07.2006 um 15:12 schrieb Niko Schwarz: > >> I want to write a Wikipedia article about "Jacketing" and I >> thought a cool squeak snippet would show both how cool I am and >> how jacketing works. Unfortunately, the snippet is growing. I >> wanted to write it neatly short, like this (no callback:) >> >> unblock: selector >> "Macht den blockierenden Aufruf selector unblockierend." >> |bs| >> bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird >> umbenannt" >> >> self >> addSelector: bs >> withMethod: (self methodAt: selector). >> self addSelector: selector >> withMethod: (self class compile: '[self perform: selector >> withArgs:args] fork') >> >> >> but as you probably noticed already, withArgs:args is not quite >> possible this way. Is there a short line of code that deals with it? > > Untested, but might work: > > unblock: selector > "Macht den blockierenden Aufruf selector unblockierend." > |bs| > bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird > umbenannt" > self > addSelector: bs > withMethod: (self methodAt: selector). > self addSelector: selector > withMethod: (self class compile: > (self standardMethodHeaderFor: bs), > '[self ', (self standardMethodHeaderFor: selector), '] fork') > > You do not need to perform if you are compiling anyway. Note that > that you need to construct 'bs' differently if selector is an > operator. Oh, actually you can even use methodHeaderFor: to get the correct arg names. - Bert - |
In reply to this post by Niko Schwarz
Thank you two, thank you Bert!
Your piece of Code looks wonderful, everyone would believe it works, unless he tested. I have no idea why it doesn't work, but it's funny, because it leaves the Browser behind broken (trying to view the method in the method browser brings up the debugger). Isn't that cool? And that's precisely why I put it (only very slightly modified) into wikipedia: http://de.wikipedia.org/wiki/Jacketing niko -- Echte DSL-Flatrate dauerhaft für 0,- Euro*! "Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl |
Am 19.07.2006 um 16:47 schrieb Niko Schwarz:
> Thank you two, thank you Bert! > > Your piece of Code looks wonderful, everyone would believe it > works, unless he tested. I have no idea why it doesn't work, but > it's funny, because it leaves the Browser behind broken (trying to > view the method in the method browser brings up the debugger). What's the error? The browser might rightfully complain that the pattern of the method source does not match the selector under which it is found in the method dictionary. > Isn't that cool? And that's precisely why I put it (only very > slightly modified) into wikipedia: > http://de.wikipedia.org/wiki/Jacketing - Bert - |
Free forum by Nabble | Edit this page |