Hi there,
for some reasons, I want to have two methods sharing the same source code base. So if I change one method within the browser, the other would change, too. Is this possible in Squeak? And, would the usual tools work with that? Regards, Martin |
I wonder what your reason is for this, maybe there is a simpler way to
achieve your goal? Matthias On Thu, May 29, 2008 at 3:39 PM, Martin Beck <[hidden email]> wrote: > Hi there, > for some reasons, I want to have two methods sharing the same source code > base. So if I change one method within the browser, the other would change, > too. Is this possible in Squeak? And, would the usual tools work with that? > > Regards, > Martin > > |
In reply to this post by Martin Beck-3
Use blocks and an accessor?
MyObject>>myBlock ^[:anObject | anObject doSomething] MyObject>>foo ^self myBlock value: 1 MyObject>>bar ^self myBlock value: 2 HTH, John Martin Beck wrote: > Hi there, > for some reasons, I want to have two methods sharing the same source > code base. So if I change one method within the browser, the other would > change, too. Is this possible in Squeak? And, would the usual tools work > with that? > > Regards, > Martin > > -- John Thornborrow http://www.pinesoft.co.uk ****************************************************************************************************************************************** This email is from Pinesoft Limited. Its contents are confidential to the intended recipient(s) at the email address(es) to which it has been addressed. It may not be disclosed to or used by anyone other than the addressee(s), nor may it be copied in anyway. If received in error, please contact the sender, then delete it from your system. Although this email and attachments are believed to be free of virus, or any other defect which might affect any computer or IT system into which they are received and opened, it is the responsibility of the recipient to ensure that they are virus free and no responsibility is accepted by Pinesoft for any loss or damage arising in any way from receipt or use thereof. ******************************************************************************************************************************************* Pinesoft Limited are registered in England, Registered number: 2914825. Registered office: 266-268 High Street, Waltham Cross, Herts, EN8 7EA |
Infact, scrap that.. just use a method and send the args.
I must be tired. John John Thornborrow wrote: > Use blocks and an accessor? > > MyObject>>myBlock > ^[:anObject | anObject doSomething] > > MyObject>>foo > ^self myBlock value: 1 > > MyObject>>bar > ^self myBlock value: 2 > > HTH, > John > > Martin Beck wrote: >> Hi there, >> for some reasons, I want to have two methods sharing the same source >> code base. So if I change one method within the browser, the other >> would change, too. Is this possible in Squeak? And, would the usual >> tools work with that? >> >> Regards, >> Martin >> >> > -- John Thornborrow http://www.pinesoft.co.uk ****************************************************************************************************************************************** This email is from Pinesoft Limited. Its contents are confidential to the intended recipient(s) at the email address(es) to which it has been addressed. It may not be disclosed to or used by anyone other than the addressee(s), nor may it be copied in anyway. If received in error, please contact the sender, then delete it from your system. Although this email and attachments are believed to be free of virus, or any other defect which might affect any computer or IT system into which they are received and opened, it is the responsibility of the recipient to ensure that they are virus free and no responsibility is accepted by Pinesoft for any loss or damage arising in any way from receipt or use thereof. ******************************************************************************************************************************************* Pinesoft Limited are registered in England, Registered number: 2914825. Registered office: 266-268 High Street, Waltham Cross, Herts, EN8 7EA |
In reply to this post by Matthias Berth-2
I want to create a much simpler collection hierarchy, which contains
only a few classes with the most important methods and not the full blown standard collection classes with many extension methods and so on. As an example, I have 4 classes for now: MyCollection, MySequencableCollection, MyArray, MyOrderedCollection. Obviously, the implementation of MyOrderedCollection is fairly the same as OrderedCollection, however I do not want to have all those funny methods in it. How can I achieve to have only those methods I need in MyOrderedCollection, without simply copying the sources and thus avoiding code duplication and later on even divergation? Martin Matthias Berth schrieb: > I wonder what your reason is for this, maybe there is a simpler way to > achieve your goal? > > Matthias > > On Thu, May 29, 2008 at 3:39 PM, Martin Beck > <[hidden email]> wrote: >> Hi there, >> for some reasons, I want to have two methods sharing the same source code >> base. So if I change one method within the browser, the other would change, >> too. Is this possible in Squeak? And, would the usual tools work with that? >> >> Regards, >> Martin >> >> > |
In reply to this post by Martin Beck-3
On Thu, 29 May 2008 15:39:58 +0200, Martin Beck wrote:
> Hi there, > for some reasons, I want to have two methods sharing the same source > code base. So if I change one method within the browser, the other would > change, too. Whenever I want that, I put the method(s) into a Trait and #use: that Trait in the respective classes. Later changing the Trait's method(s) also changes the Trait user's method (traits only recompiles its used methods if they do super send). > Is this possible in Squeak? And, would the usual tools work with that? Trait has not so sophisticated tool support but it works for the case that you+me described. /Klaus > Regards, > Martin > > |
Klaus D. Witzel schrieb:
> On Thu, 29 May 2008 15:39:58 +0200, Martin Beck wrote: > >> Hi there, >> for some reasons, I want to have two methods sharing the same source >> code base. So if I change one method within the browser, the other >> would change, too. > > Whenever I want that, I put the method(s) into a Trait and #use: that > Trait in the respective classes. Later changing the Trait's method(s) > also changes the Trait user's method (traits only recompiles its used > methods if they do super send). > classes or methods are part of the Collection hierarchy, which I of course don't want to change... Otherwise, a trait would be a useful solution, I agree. Martin |
On Thu, 29 May 2008 17:16:32 +0200, Martin Beck wrote:
> Klaus D. Witzel schrieb: >> On Thu, 29 May 2008 15:39:58 +0200, Martin Beck wrote: >> >>> Hi there, >>> for some reasons, I want to have two methods sharing the same source >>> code base. So if I change one method within the browser, the other >>> would change, too. >> Whenever I want that, I put the method(s) into a Trait and #use: that >> Trait in the respective classes. Later changing the Trait's method(s) >> also changes the Trait user's method (traits only recompiles its used >> methods if they do super send). >> > Yupp, I know that, but as my other post indicated, one half of these > classes or methods are part of the Collection hierarchy, which I of > course don't want to change... Otherwise, a trait would be a useful > solution, I agree. Okay, Traits was meant for the general case ;) If I do the above to collection (I more often do that to compiler), and I do want the same interface and the closest possible implementation (=same source code), then I put this in MyClass class initialization initialize "MyClass initialize" (self recompile: #thisNthat from: DonorClass; organization) classify: #thisNthat under: #'DonorClass-method' ditto for each selector (or loop over an array of selectors). And if some DonorClass method had changed, just select and eval the comment :) /Klaus > Martin > > |
In reply to this post by Martin Beck-3
Martin Beck <martin.beck <at> hpi.uni-potsdam.de> writes:
> > Hi there, > for some reasons, I want to have two methods sharing the same source > code base. So if I change one method within the browser, the other would > change, too. Is this possible in Squeak? And, would the usual tools work > with that? > > Regards, > Martin > > It is as simple as (iff you ignore tool support) A compile: 'foo ^ 42'. m := A methodDict at: #foo. B methodDict at: #bar putNoBecome: m. B new bar. "=> 42" (at hard-core squeakers, why does a simple #at:put: not work?) cheers, AA |
2008/5/29 Adrian Kuhn <[hidden email]>:
> Martin Beck <martin.beck <at> hpi.uni-potsdam.de> writes: > >> >> Hi there, >> for some reasons, I want to have two methods sharing the same source >> code base. So if I change one method within the browser, the other would >> change, too. Is this possible in Squeak? And, would the usual tools work >> with that? >> >> Regards, >> Martin >> >> > > It is as simple as (iff you ignore tool support) > > A compile: 'foo ^ 42'. > m := A methodDict at: #foo. > B methodDict at: #bar putNoBecome: m. > B new bar. "=> 42" > > (at hard-core squeakers, why does a simple #at:put: not work?) > lead to unexpected results. > cheers, > AA > > > > > -- Best regards, Igor Stasenko AKA sig. |
In reply to this post by Adrian Kuhn
Hi!
There are many ways in squeak to have code in 1 place but use it from many. Of course the most standard way is always a shared superclass; if that is not possible then there are many other ways... Adrian Kuhn wrote: > It is as simple as (iff you ignore tool support) > > A compile: 'foo ^ 42'. > m := A methodDict at: #foo. > B methodDict at: #bar putNoBecome: m. > B new bar. "=> 42" Yep this is fun, and you dont need to learn (proper) Traits. compare Behavior:#addSelectorSilently:withMethod: Make sure everything is still working. In fact SystemBrowser will not show that B has an instancemethod #bar, you have to register the selector for it to notice, something like that. And code-repositories and fileouts/changes might not notice anything, so consider it a hack. You might think that the method is hidden from the squeak user then but "B selectors" will return an array of selectors including #bar. Its also fun: B methodDict: A methodDict :-) Greetings Bernd |
Free forum by Nabble | Edit this page |