Hacker News new | ask | show | jobs
by thisrod 3465 days ago
Smalltalk had a neat solution to this. You gave some arguments and a result, then it tried all the methods with the right types, and listed the ones that gave the result. Searching for '(a b c) and 'a would tell you what car is called in Smalltalk.
3 comments

prolog does this too, but it's not enough. if you don't have enough data, you could find a match that will fail in the future.

To answer OP's question, the reason people rewrite is that it's "faster" to write a new one than find what's out there

OR

I don't want an entire house when all I want is a faucet. Today if you want a faucet. you might have to do something such as house = new House(); faucet = house.getFaucet(); So you have to tear apart/copy and paste the code, if it's loosely coupled enough, you find yourself dealing with all the dependencies.

This is a question lots of people have been asking tho, checkout this talk from the creator of Erlang asking the same question https://www.youtube.com/watch?v=lKXe3HUG2l4

The house analogy makes sense - I need to research Smalltalk and Prolog Checking out the video - thanks
this sounds cool, but the order of parameters matters.

for example, in the case of matrix multiplication, A * B is valid, B * A could be invalid. How to pass the parameters in right order for searching?

How did it avoid calling methods with dangerous side effects?