4 ms·
Arguably the S3 object system is also "functional" in spirit, even if it's single-dispatch. https://arxiv.org/pdf/1409.3531.pdf https://arxiv.org/pdf/1409.3531
by kgwgk 5y ago
Arguably the S3 object system is also "functional" in spirit, even if it's single-dispatch.
https://arxiv.org/pdf/1409.3531.pdf https://arxiv.org/pdf/1409.3531.pdf
Object-Oriented Programming, Functional Programming and R (John M. Chambers)
"Chambers and Hastie (1992), in the discussion of classes and methods, noted that S differed from other OOP languages because of its functional programming style. In fact, this version of functional OOP finessed the resulting distinction from encapsulated OOP in two ways. First, the methods were dispatched according to a single argument, the first formal argument of the generic function in principle. As a result, the methods were unambiguously associated with a single class, as they would be in encapsulated OOP. Methods were actually dispatched on either argument to the usual binary operators, but a number of encapsulated OOP languages do the same, under the euphemism of operator overloading.
"Second, the question of whether methods belonged to a class or a function was avoided by not having them belong to either. Methods were assigned as ordinary functions and identified by the pattern of their name: “function.class”. In any case, there were no class objects and generic functions were ordinary functions that invoked UseMethod() to select and call the appropriate method. Neither the function nor the class was able to own the methods."