[Pharo-project] Problem with Traits and #initialize.
1) Browse the example Trait1 and you will see methods like: Trait1 >> c ^ 'Trait1>>c' and: Trait1 >> c1 ^ 'Trait1>>c1' 2) Now, execute "Trait1 initialize" 3) BOOM. Trait1 has no longo any method. In the browse they are shown like: Trait1 >> c "This method does not exist." self halt. Trait2 >> c1 "This method does not exist." self halt. .... If I see Trait >> initialize super initialize. classTrait := ClassTrait for: self and then ClassTrait for: "This method does not exist." self halt. wtf ?? that method is removed? this even happens before doing Trait1 initialize. so...any idea? -- Mariano http://marianopeck.wordpress.com
why would it make sense to send initialize? Stef On Jun 4, 2011, at 11:42 AM, Mariano Martinez Peck wrote:
1) Browse the example Trait1 and you will see methods like: Trait1 >> c
^ 'Trait1>>c'
and:
Trait1 >> c1
^ 'Trait1>>c1'
2) Now, execute "Trait1 initialize" 3) BOOM. Trait1 has no longo any method. In the browse they are shown like:
Trait1 >> c "This method does not exist." self halt.
Trait2 >> c1 "This method does not exist." self halt.
....
If I see Trait >> initialize super initialize. classTrait := ClassTrait for: self
and then ClassTrait for: "This method does not exist." self halt.
wtf ?? that method is removed? this even happens before doing Trait1 initialize.
so...any idea?
-- Mariano http://marianopeck.wordpress.com
Did you look at TraitBehavior>>#initialize and Behavior>>#initialize? They both clear the method dictionary, reset superclass, clear users and traits, etc. What you observe is what is implemented in these methods. Normally you should never call class-side initialize methods manually, the system does this for you if necessary. Lukas On 4 June 2011 12:04, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
why would it make sense to send initialize?
Stef
On Jun 4, 2011, at 11:42 AM, Mariano Martinez Peck wrote:
1) Browse the example Trait1 Â and you will see methods like: Trait1 >> c
  ^ 'Trait1>>c'
and:
Trait1 >> c1
  ^ 'Trait1>>c1'
2) Now, execute "Trait1 initialize" 3) BOOM. Trait1 has no longo any method. In the browse they are shown like:
Trait1 >> c   "This method does not exist."   self halt.
Trait2 >> c1 Â Â "This method does not exist." Â Â self halt.
....
If I see Trait >> initialize   super initialize.   classTrait := ClassTrait for: self
and then ClassTrait for: Â Â "This method does not exist." Â Â self halt.
wtf ?? Â that method is removed? this even happens before doing Trait1 initialize.
so...any idea?
-- Mariano http://marianopeck.wordpress.com
-- Lukas Renggli www.lukas-renggli.ch
On Sat, Jun 4, 2011 at 12:28 PM, Lukas Renggli <renggli@gmail.com> wrote:
Did you look at TraitBehavior>>#initialize and Behavior>>#initialize? They both clear the method dictionary, reset superclass, clear users and traits, etc.
Thanks for the point. I can see now.
What you observe is what is implemented in these methods. Normally you should never call class-side initialize methods manually, the system does
yeah, the system *should* do it for me. I cannot reproduce it, but I find myself several times having to explicitly send class side #initialize becasue Monticello did not do it.
this for you if necessary.
Lukas
On 4 June 2011 12:04, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
why would it make sense to send initialize?
Stef
On Jun 4, 2011, at 11:42 AM, Mariano Martinez Peck wrote:
1) Browse the example Trait1 and you will see methods like: Trait1 >> c
^ 'Trait1>>c'
and:
Trait1 >> c1
^ 'Trait1>>c1'
2) Now, execute "Trait1 initialize" 3) BOOM. Trait1 has no longo any method. In the browse they are shown like:
Trait1 >> c "This method does not exist." self halt.
Trait2 >> c1 "This method does not exist." self halt.
....
If I see Trait >> initialize super initialize. classTrait := ClassTrait for: self
and then ClassTrait for: "This method does not exist." self halt.
wtf ?? that method is removed? this even happens before doing Trait1 initialize.
so...any idea?
-- Mariano http://marianopeck.wordpress.com
-- Lukas Renggli www.lukas-renggli.ch
-- Mariano http://marianopeck.wordpress.com
What you observe is what is implemented in these methods. Normally you should never call class-side initialize methods manually, the system does
yeah, the system *should* do it for me. I cannot reproduce it, but I find myself several times having to explicitly send class side #initialize becasue Monticello did not do it.
Monticello sends class side #initialize whenever it loads a new version of that method, that is on initial load and/or when it updates a method after load/merge. It does not send #initialize in any other case and it does not send super #initialize methods (that would break the system in most cases). Note that this has exactly the same semantics as with change-sets: If a change-set includes a class-side initialize method, it is executed at the end of the file-in.
((PackageInfo named: 'XXX') classes select: [:each | each isBehavior ]) do: [:each | each initialize]
Do Gofer new package: 'XXX'; reinitialize It does the "right" thing. Lukas -- Lukas Renggli www.lukas-renggli.ch
On Sat, Jun 4, 2011 at 12:04 PM, Stéphane Ducasse <stephane.ducasse@inria.fr
wrote:
why would it make sense to send initialize?
Because the system has fucking names. PackageInfo >> classes answers both, traits and classes. I wanted to send #initialize to all classes of a package. Of course, I did a workaround: ((PackageInfo named: 'XXX') classes select: [:each | each isBehavior ]) do: [:each | each initialize] Funny, I reported exactly the same 1 year ago: http://forum.world.st/Bug-PackageInfo-classes-return-also-Traits-tp2165137p2... what a bad memory I have
Stef
On Jun 4, 2011, at 11:42 AM, Mariano Martinez Peck wrote:
1) Browse the example Trait1 and you will see methods like: Trait1 >> c
^ 'Trait1>>c'
and:
Trait1 >> c1
^ 'Trait1>>c1'
2) Now, execute "Trait1 initialize" 3) BOOM. Trait1 has no longo any method. In the browse they are shown like:
Trait1 >> c "This method does not exist." self halt.
Trait2 >> c1 "This method does not exist." self halt.
....
If I see Trait >> initialize super initialize. classTrait := ClassTrait for: self
and then ClassTrait for: "This method does not exist." self halt.
wtf ?? that method is removed? this even happens before doing Trait1 initialize.
so...any idea?
-- Mariano http://marianopeck.wordpress.com
-- Mariano http://marianopeck.wordpress.com
participants (3)
-
Lukas Renggli -
Mariano Martinez Peck -
Stéphane Ducasse