Is it possible to overload operators in Smalltalk?
I am looking for tutorials/examples.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Method overloading is not possible in Smalltalk. Instead, a combination of method overriding and a technique called double dispatch is used to implement the same behavior as operator overloading in other languages.
You can find an example implementation in the mathematical operators
+,*,/,-(which are binary messages in Smalltalk). Here is the idea: the implementation ofInteger>>+sends a message#addWithInteger:to its argument. The implementation of#addWithInteger:is implemented on each Magnitude subclass, such as to specialize addition of Int+Int, Float+Int, etc…