Category:Smalltalk: Difference between revisions

m
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:
<lang smalltalk>factorial
^ (self <= 1) ifTrue:[1] ifFalse:[self * (self-1) factorial]</lang>
ifTrue:[1]
ifFalse:[ self * (self-1) factorial ]</lang>
(here 'self' is the Integer receiver object, and "ˆ" returns a value from the message send).
 
Anonymous user