I have a method to calculate the exponent, but it doesnt like the c := c * a. If i do something like c := a. it works and im unsure why its behaving this way when i try and do c := c *a.. Im new to Smalltalk, so maybe its just something im missing. Im using Pharo as my implementaton.
testPow: i1 exp: i2
"Testing exponent. i1 and i2 are integers, we calculate and then return the value as a Church numeral"
| a b c |
a := i1.
b := i2.
1 to: b do: [ :i |
c:= c*a.
].
^c.
You need to initialise
cbefore using it. With your statement:it works because
ahas a value. With:it won’t work because the first time through the loop,
cwill not be initialised to anything useful.Just change your initialisation section to: