Category:Smalltalk: Difference between revisions

Content added Content deleted
Line 461: Line 461:


=== Control Structures ===
=== Control Structures ===
As mentioned above, these are defined as messages and their implementation is found in the corresponding receiver classes. For illustration, here is how conditional execution ('if-then-else') is implemented in Smalltalk. There are two boolean objects named "true" and "false", which are singletons of corresponding classes named "True" and "False" (both inherit from Boolean, which inherits from Object). It is essential, that these are singletons, and that typical relational operators like "<", ">" etc. return one of those two.
As mentioned above, these are defined as messages and their implementation is found in the corresponding receiver's class. For illustration, here is how conditional execution ('if-then-else') is implemented in Smalltalk. There are two boolean objects named "true" and "false", which are singletons of corresponding classes named "True" and "False" (both inherit from Boolean, which inherits from Object). It is essential, that these are singletons, and that typical relational operators like "<", ">" etc. return one of those two.
<br>Then, in the True class, define:
<br>Then, in the True class, define:
<lang smalltalk>ifYouAreTrueThenDo: arg1 ifNotThenDo: arg2
<lang smalltalk>ifYouAreTrueThenDo: arg1 ifNotThenDo: arg2