|
|
|
|
|
by hota_mazi
2655 days ago
|
|
But there's nothing specific about message passing to that example, you can do this with regular function calling: For example in Kotlin: class Boolean {
fun ifTrue(closure: -> ())
fun ifFalse(... whatever)
}
a.ifTrue { /* do something */ }
|
|
IIRC, Smalltalk has Boolean class and two subclasses of Boolean: True and False. There is a single method with two arguments (:ifTrue:ifFlase). The method is then overloaded. True calls ifTrue argument. Flase calls ifFalse argument. This is happening dynamically, at runtime. Again, the mechanism is generic enough to fully replace all use cases of "traditional" if/else constructs.
Clearly, you haven't thought this through.
Edit: People here would do well to read this: https://pozorvlak.livejournal.com/94558.html