Anonymous classes in Pharo 3 - must be instances of Class, not Behavior
Hi folks, I was updating my lecture on Reflection for the Software Design and Evolution course, and I see now that anonymous classes can no longer be instances of Behavior but must be instances of Class. If you try to compile a method on an instance of Behavior, it fails. (basicLocalSelectors is not understood) Am I missing something? Cheers, Oscar testPrimitiveChangeClassTo | anonClass browser | anonClass := Class new. âmust be Class, not Behavior" anonClass superclass: Browser. anonClass setFormat: Browser format. browser := Browser new. browser primitiveChangeClassTo: anonClass new. anonClass compile: 'thisIsATest ^ 2'. self assert: browser thisIsATest = 2. self should: [Browser new thisIsATest] raise: MessageNotUnderstood.
Following up: Behavior new compile: 't ^ trueâ fails since #compile: is defined in TBehavior and depends on #basicLocalSelectors which is defined only in Class, MetaClass and TraitBehavior. It seems like #basicLocalSelectors should be abstract in TBehavior. Alternatively the implementation should be moved to TBehavior and the field localSelectors should be pushed up to Behavior. Am I missing something? Oscar On 29 Aug 2014, at 12:26 , Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote:
Hi folks,
I was updating my lecture on Reflection for the Software Design and Evolution course, and I see now that anonymous classes can no longer be instances of Behavior but must be instances of Class. If you try to compile a method on an instance of Behavior, it fails. (basicLocalSelectors is not understood)
Am I missing something?
Cheers, Oscar
testPrimitiveChangeClassTo | anonClass browser |
anonClass := Class new. âmust be Class, not Behavior" anonClass superclass: Browser. anonClass setFormat: Browser format.
browser := Browser new. browser primitiveChangeClassTo: anonClass new. anonClass compile: 'thisIsATest ^ 2'.
self assert: browser thisIsATest = 2. self should: [Browser new thisIsATest] raise: MessageNotUnderstood.
2014-08-29 13:38 GMT+02:00 Oscar Nierstrasz <oscar.nierstrasz@gmail.com>:
Following up:
Behavior new compile: 't ^ trueâ
fails since #compile: is defined in TBehavior and depends on #basicLocalSelectors which is defined only in Class, MetaClass and TraitBehavior.
It seems like #basicLocalSelectors should be abstract in TBehavior. Alternatively the implementation should be moved to TBehavior and the field localSelectors should be pushed up to Behavior. Am I missing something?
Yep, I think you are right. Last year I did a lot of modifications in Behavior, TBehavior, Class, etc. These changes were made to make classes and traits polymorphic. If I remember correctly, the instance variable localSelectors was not moved to Behavior because it was not possible to push up that instance variable (there were a lot of errors since it is one of the core classes). If you look at the traits hierarchy, localSelectors is in TraitBehavior, not in Trait. So moving the instance variable localSelectors to Behavior and then abstract basicLocalSelectors in TBehavior would be very good
Oscar
On 29 Aug 2014, at 12:26 , Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote:
Hi folks,
I was updating my lecture on Reflection for the Software Design and
Evolution course, and I see now that anonymous classes can no longer be instances of Behavior but must be instances of Class. If you try to compile a method on an instance of Behavior, it fails. (basicLocalSelectors is not understood)
Am I missing something?
Cheers, Oscar
testPrimitiveChangeClassTo | anonClass browser |
anonClass := Class new. âmust be Class, not Behavior" anonClass superclass: Browser. anonClass setFormat: Browser format.
browser := Browser new. browser primitiveChangeClassTo: anonClass new. anonClass compile: 'thisIsATest ^ 2'.
self assert: browser thisIsATest = 2. self should: [Browser new thisIsATest] raise: MessageNotUnderstood.
On 29 août 2014, at 13:38, Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote:
Following up:
Behavior new compile: 't ^ trueâ
fails since #compile: is defined in TBehavior and depends on #basicLocalSelectors which is defined only in Class, MetaClass and TraitBehavior.
It seems like #basicLocalSelectors should be abstract in TBehavior. Alternatively the implementation should be moved to TBehavior and the field localSelectors should be pushed up to Behavior. Am I missing something?
You're right, it should be possible to compile methods into an instance of behavior. IIRW, it was possible in Pharo 2 but we didn't pay enough attention to ensure that it is always possible. So if we can make it work again we should add your test somewhere for that. About moving localSelectors to Behavior: I'm not sure that Behavior should be aware of traits. I prefer to keep Behavior minimal (it is already too messy IMO). Also for Pharo 4 there is other issues introduced by the integration of slots (slots are now needed by Opal for compilation): - we should move slot API to Behavior - make sure that iv and format ivs are consistent with each other So there is some work to be done to make it work again...
Oscar
On 29 Aug 2014, at 12:26 , Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote:
Hi folks,
I was updating my lecture on Reflection for the Software Design and Evolution course, and I see now that anonymous classes can no longer be instances of Behavior but must be instances of Class. If you try to compile a method on an instance of Behavior, it fails. (basicLocalSelectors is not understood)
Am I missing something?
Cheers, Oscar
testPrimitiveChangeClassTo | anonClass browser |
anonClass := Class new. âmust be Class, not Behavior" anonClass superclass: Browser. anonClass setFormat: Browser format.
browser := Browser new. browser primitiveChangeClassTo: anonClass new. anonClass compile: 'thisIsATest ^ 2'.
self assert: browser thisIsATest = 2. self should: [Browser new thisIsATest] raise: MessageNotUnderstood.
Thanks for the clarifications! Oscar On 29 Aug 2014, at 14:01 , Camille Teruel <camille.teruel@gmail.com> wrote:
On 29 août 2014, at 13:38, Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote:
Following up:
Behavior new compile: 't ^ trueâ
fails since #compile: is defined in TBehavior and depends on #basicLocalSelectors which is defined only in Class, MetaClass and TraitBehavior.
It seems like #basicLocalSelectors should be abstract in TBehavior. Alternatively the implementation should be moved to TBehavior and the field localSelectors should be pushed up to Behavior. Am I missing something?
You're right, it should be possible to compile methods into an instance of behavior. IIRW, it was possible in Pharo 2 but we didn't pay enough attention to ensure that it is always possible. So if we can make it work again we should add your test somewhere for that. About moving localSelectors to Behavior: I'm not sure that Behavior should be aware of traits. I prefer to keep Behavior minimal (it is already too messy IMO). Also for Pharo 4 there is other issues introduced by the integration of slots (slots are now needed by Opal for compilation): - we should move slot API to Behavior - make sure that iv and format ivs are consistent with each other So there is some work to be done to make it work again...
Oscar
On 29 Aug 2014, at 12:26 , Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote:
Hi folks,
I was updating my lecture on Reflection for the Software Design and Evolution course, and I see now that anonymous classes can no longer be instances of Behavior but must be instances of Class. If you try to compile a method on an instance of Behavior, it fails. (basicLocalSelectors is not understood)
Am I missing something?
Cheers, Oscar
testPrimitiveChangeClassTo | anonClass browser |
anonClass := Class new. âmust be Class, not Behavior" anonClass superclass: Browser. anonClass setFormat: Browser format.
browser := Browser new. browser primitiveChangeClassTo: anonClass new. anonClass compile: 'thisIsATest ^ 2'.
self assert: browser thisIsATest = 2. self should: [Browser new thisIsATest] raise: MessageNotUnderstood.
On 29/8/14 14:01, Camille Teruel wrote: > On 29 août 2014, at 13:38, Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote: > >> Following up: >> >> Behavior new compile: 't ^ trueâ >> >> fails since #compile: is defined in TBehavior and depends on #basicLocalSelectors which is defined only in Class, MetaClass and TraitBehavior. >> >> It seems like #basicLocalSelectors should be abstract in TBehavior. >> Alternatively the implementation should be moved to TBehavior and the field localSelectors should be pushed up to Behavior. Am I missing something? > You're right, it should be possible to compile methods into an instance of behavior. > IIRW, it was possible in Pharo 2 but we didn't pay enough attention to ensure that it is always possible. So if we can make it work again we should add your test somewhere for that. > About moving localSelectors to Behavior: I'm not sure that Behavior should be aware of traits. I prefer to keep Behavior minimal (it is already too messy IMO). Yes I agree too. > Also for Pharo 4 there is other issues introduced by the integration of slots (slots are now needed by Opal for compilation): > - we should move slot API to Behavior > - make sure that iv and format ivs are consistent with each other > So there is some work to be done to make it work again... :) > >> Oscar >> >> On 29 Aug 2014, at 12:26 , Oscar Nierstrasz <oscar.nierstrasz@gmail.com> wrote: >> >>> Hi folks, >>> >>> I was updating my lecture on Reflection for the Software Design and Evolution course, and I see now that anonymous classes can no longer be instances of Behavior but must be instances of Class. If you try to compile a method on an instance of Behavior, it fails. (basicLocalSelectors is not understood) >>> >>> Am I missing something? >>> >>> Cheers, >>> Oscar >>> >>> testPrimitiveChangeClassTo >>> | anonClass browser | >>> >>> anonClass := Class new. âmust be Class, not Behavior" >>> anonClass superclass: Browser. >>> anonClass setFormat: Browser format. >>> >>> browser := Browser new. >>> browser primitiveChangeClassTo: anonClass new. >>> anonClass compile: 'thisIsATest ^ 2'. >>> >>> self assert: browser thisIsATest = 2. >>> self should: [Browser new thisIsATest] >>> raise: MessageNotUnderstood. >>> >>> >> > >
participants (4)
-
Camille Teruel -
Oscar Nierstrasz -
Sebastian Tleye -
stepharo