It seems that someone needed an optimized factorial-routine⦠The problem on the other hand is, that the machine friendly code is much less âdidactical" than the human friendly common implementation. To have both I propose to add the human friendly clear and short version as comment. Its a bit like some primitive methods were after the primitive call there is the smalltalk version as well (VisualWorks). Regards, Bernhard Höfner
... The algos are different:
Pharo 8: Integer>>factorial "Answer the factorial of the receiver."
self = 0 ifTrue: [^ 1]. self > 0 ifTrue: [^ self * (self - 1) factorial]. self error: 'Not valid for negative integers'
Pharo 9:
Integer>>factorial | nex nexnext acc | "Guard for know cases (0,1,2,error)" self < 3 ifTrue: [ ^ self < 0 ifTrue: [ self error: 'Not valid for negative integers' ] ifFalse: [ self > 0 ifTrue: [ self ] ifFalse: [ 1 ] ] ]. acc := 2. nex := 2. nexnext := 10.
self // 2 - 1 timesRepeat: [ nex := nex + nexnext. nexnext := nexnext + 8. acc := acc * nex ]. self odd ifTrue: [ acc := acc * self ]. ^ acc
...