articles/smalltalk.md: add factorial example

This commit is contained in:
tocariimaa 2025-03-08 20:06:35 -03:00
parent ec1e691191
commit b899e7e291

View file

@ -61,6 +61,17 @@ String extend [
Transcript show: 'smalltalk' removeVowels; cr. "==> smlltlk"
```
### Factorial
Smalltalk already provides a method `factorial` but that's cheating so we will implement it here:
```smalltalk
| n res |
res := 1.
n := 5.
1 to: n do: [:i | res := res * i].
Transcript show: 'fact of ', (n asString), ' = ', (res asString); cr.
```
Homework: add this as a method by extending the `Number` class.
TODO
## Resources