Hacker News new | ask | show | jobs
by pjmlp 3878 days ago
Multi-methods are how Lisp based languages have done OO since the early days.

LOOPS in Interlisp-D, here for a time travel to Xerox PARC.

http://www.softwarepreservation.org/projects/LISP/interlisp_...

Check the "LOOPS, A Friendly Prime" book.

Meta-methods are at the core of CLOS, Common Lisp Object System, made famous with the "The Art of Metaobject Protocol" book.

http://www.amazon.de/The-Metaobject-Protocol-Gregor-Kiczales...

They are also used by Dylan, the Lisp with Algol like syntax developed by Apple,

Protocols provide the same type of polymorphism offered by Objective-C protocols, Java/C# interfaces, Go interfaces, ...

Many mainstream developers might only know one way of doing OO, but back in the day we could choose between Smalltalk, Lisp, Beta, Eiffel, Sather, C++, Modula-3, Oberon, Component Pascal, SELF, .....

Each had their own view how encapsulation, polymorphism, message dispatch, type extensions should take place.

So it is kind of funny to have some in FP languages bashing OO, while successful FP languages are actually hybrid. At the same time having people in teh OO side bashing FP, while their languages keep absorbing FP concepts.

Eventually we will get back to Smalltalk and Lisp, which already provided both ways in the late 70's.

1 comments

But protocols and mulitmethods are different from OO in the sense that the functions are decoupled from the state. You don't store state in a protocol, you just define an interface. That's pretty different from the way most people think about OO in c++, java, swift, objective-c, etc. In Clojure, you have Records and maps, which hold your "state" or your values, and you have protocols which define your functions, and the two are isolated from each other and not attached in any way. That's quite different from OO in general, don't you think?
No, because there isn't one way of doing OO.

Just go read the Xerox PARC papers on how to do OO in Lisp, for example.

Back when OO was new there were multiple ways of how to do OO.

Some languages used the Smalltalk approach.

Others took the Simula approach where objects were an evolution of modules that could be extend and manipulated.

And there were lots of other options scattered around OOPSLA papers.

What happens is that there are now a couple of generations of new developers that didn't live through the procedural to object oriented programming revolution, nor were doing their CS degree in those days, so many understand OO as C++, Java et al do it and think no other way is possible.

The way Lisp does it, is quite common in the OO languages that offer multi-dispatch in method binding.

Since all method arguments types are used in the method resolution, it doesn't make sense to bind the methods to a specific object.

LOOPS and CLOS books/papers are pretty clear that they are doing OOP.