Hi,
This example in the slides of Pharo MOOC, week 7, is broken in Pharo
7.0 (the variable newClass is not used, thus it has been removed):
| behavior model |
behavior := Behavior new.
behavior superclass: Model.
behavior setFormat: Model format.
model := Model new.
model primitiveChangeClassTo: behavior new.
self assert: model class = behavior.
self assert: model class superclass = Model.
behavior compile: 'foo ^ 2'.
self assert: model foo = 2.
self should: [Model new foo] raise: MessageNotUnderstood
(slide 14 in
http://rmod-pharo-mooc.lille.inria.fr/MOOC/Slides/Week7/C019-W7S04-OtherReflective.pdf)
The code is broken because there is no method Behavior>>classInstaller,
and the message classInstaller is sent to self in Behavior>>superclass:.
Adding a Behavior>>superclass2: to Pharo 7.0, copied from Pharo 6.1
Behavior>>superclass:, and using Behavior>>superclass2: in the example:
| behavior model |
behavior := Behavior new.
behavior superclass2: Model. "<-------"
behavior setFormat: Model format.
model := Model new.
model primitiveChangeClassTo: behavior new.
self assert: model class = behavior.
self assert: model class superclass = Model.
behavior compile: 'foo ^ 2'.
self assert: model foo = 2.
self should: [Model new foo] raise: MessageNotUnderstood
the code works again and the example is good. However, this is only an
ugly workaround.
Thus:
I do not know why Behavior>>superclass: was changed in Pharo 7.0 but I
guess it was not an accident. I assume it has to do with deep changes
in the low level structure of the implementation of the language,
having to do with slots, etc.
I have browsed Pharo issues in github but I did not find anything
related. Also, I'm not sure this problem qualifies as an "issue".
So, my question is. Is it possible to easily adapt the example to the
new Pharo 7.0? (with no silly workarounds, I mean).
Thanks in advance and, as usual, apologies if the question is trivial
and/or stupid.
Bests,
Jordi
PS: Any Pharoer in CCCamp?
--
Jordi Delgado
Computer Science Department - Universitat Politècnica de Catalunya
Campus Nord, Omega building,
Office S115 c/Jordi Girona Salgado, 1-3
08034 Barcelona, Spain.
Phone: +34.93.413.40.18
Public Key:
https://pgp.mit.edu/pks/lookup?op=get&search=0xB7911543AD9E79A8