Re:Ask HN: 30y After 'On Lisp', PAIP etc., Is Lisp Still "Be...
by kazinator on Monday June 10, 2024 @09:15PM
(#40641208)
I replied to this not knowing exactly where the goalposts are.
Indeed, in C++, our a + b expression is statically analyzed to be working with specific types; the declared types of a and b. When that code is compiled, it will work with no other types.
However, if we anticipate that kind of extension, we can have a be a reference to some numeric_base class where operator + is a virtual function.
With some help from a bit of platform specific coding, we can have dynamically loaded modules which can provide new classes derived from numeric_base that ca be passed to existing code in the program which uses + on numeric_base.
Unless I'm mistaken (which I may well be), you can't do that at runtime, only at compile time.