← Back to context

Comment by taejo

8 years ago

This technique is limited by the fact that it only works if all the messages are sent to x, rather than x being sent some message.

You mean "rather than x being sent to some message"? E.g. 0 > x wouldn't work, because the message #> is sent to 0 with x as an argument? In a case like that you can still make it work by exploiting the fact that arithmetic and comparison operators implement double dispatch. The implementation of > for an Integer would send a message to x:

  Integer::> aNumber
    ^x adaptToInteger: self andCompare: #<

Even if x is passed as an argument, to interact with it at some point somebody has to send a message to it. I agree that it can become unwieldy to intercept all possible messages, but for a well-defined subset in your DSL, this can usually be done.