I'm reading through Seven Programming Languages in Seven Weeks, and one of the problems states:
How would you change /
to return 0
if the denominator is zero?
I first tried defining my own /
and proxying its implementation to the original /
method like this:
Number oldSlash := Number getSlot("/")
Number / = method(x, Number oldSlash(x))
However that was not working for me. After doing some Googling I found a similar piece of code. The code I found was using self
in the implementation of the method. So, I tried using self
and it seemed to work just fine:
Number oldSlash := Number getSlot("/")
Number / = method(x, self oldSlash(x))
My question is: Why does this work when the keyword self
is used, and why does it not work when Number
is used instead?