Merci bien. Je trouve le commentaire qui explique comment le compilateur optimise le code trés intérressant (et cela explique aussi le commentaire dans le code de Squeak). Moi qui trouvait justement que la définition récursive du whileTrue était un peu barbare :) Mais cela ne m'explique toujours pas l'implémentation du whileTrue dans Squeak ?
Loïs
Le dimanche 19 février 2006 à 10:08 +0100, stéphane ducasse a écrit :
en VisualWorks
ils ont la definition suivante
whileTrue: aBlock "Evaluate the argument, aBlock, as long as the value of the receiver is true."
^self value ifTrue: [aBlock value. [self value] whileTrue: [aBlock value]]
"This method is inlined if both the receiver and the argument are literal blocks. In all other cases, the code above is run. Note that the code above is defined recursively. However, to avoid actually building an activation record each time this method is invoked recursively, we have used the '[...] whileTrue: [..]' form in the last line, rather than the more concise 'self whileTrue: aBlock'. Using literal blocks for both the receiver and the argument allows the compiler to inline #whileTrue:, which (in the absence of type inferencing) could not be done if we were to use 'self whileTrue: aBlock'." _______________________________________________ Squeak-fr mailing list Squeak-fr@lists.squeakfoundation.org http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-fr