Hi,
 when I'm teaching OO one of the most interesting subjects is the
implementation of control flow structures with closures.
 Having to implement #ifTrue: only with objects and messages produces in
some students the "click" we are looking for, the "ah!" that makes them see
the real difference with procedural languages and most no pure object
languages (java, c#, etc).
 When teaching the execution model, I use the #whileTrue: implementation to
show them that it is also possible to implement such a thing with just
objects and messages.
 The last semester to my surprise I saw that the #whileTrue: implementation
in Pharo is cumbersome, at least for teaching porpoises, because it is based
on the "hidden" detail that #whileTrue: is inlined, therefore never sent and
its method never executed. The VisualWorks implementation is clearer because
it is a recursive implementation that seems to work without knowing that
#whileTrue: is inlined (and has a nice comment that explains that
implementation detail).
 Anyway, just for teaching porpoises I thought that providing another
implementation would be nice, an implementation based on the execution
context, an implementation completely based on objects and messages. For
example:

whileTrue: aBlock

   self value ifTrue: [
aBlock value.
thisContext restart ]

 I think it is an interesting example that allows the students to see how we
can manipulate the execution environment from inside Smalltalk itself...
 Anyway, just a comment... not sure if it makes sense to change the
implementation just because of this, but maybe putting a comment explaining
this option would be nice.

 Bye,
 Hernan.
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to