Category:Smalltalk: Difference between revisions

Content added Content deleted
Line 511: Line 511:
For example, if asked to provide an example for a factorial function, a typical Smalltalk solution would be to define a method in the Integer class called "factorial", which might look like the following naïve version:
For example, if asked to provide an example for a factorial function, a typical Smalltalk solution would be to define a method in the Integer class called "factorial", which might look like the following naïve version:
<lang smalltalk>factorial
<lang smalltalk>factorial
^ (self <= 1) ifTrue:[1] ifFalse:[self * (self-1) factorial]</lang>
^ (self <= 1)
ifTrue:[1]
ifFalse:[ self * (self-1) factorial ]</lang>
(here 'self' is the Integer receiver object, and "ˆ" returns a value from the message send).
(here 'self' is the Integer receiver object, and "ˆ" returns a value from the message send).