Skip to content

Function Overloading

Ashok Khanna edited this page Dec 31, 2021 · 2 revisions

Function overloading doesn't make much sense (when it comes to varying parameters) as you can't dynamically call functions with a varying number of parameters

However has use when trying to pass through variable amount of keyword parameters in macros. We are talking about &key &allow-other-keys here

Useful thread

https://groups.google.com/g/comp.lang.lisp/c/rvE7Yd3GEwo/m/9c3e1ivMBuwJ

Note that it becomes NLP like then, and documentation becomes hard

No native concept of function overloading in CL

CLOS is different - polymorphism & dynamic dispatch vs. ...

Don't worry about naming, since you can have multiple packages and shadow each other that way

https://stackoverflow.com/questions/14851296/can-functions-be-overloaded-in-lisp-like-they-can-be-in-c

https://groups.google.com/g/comp.lang.lisp/c/LTxR2mAEu-g

KMP:

It IS intended that you sometimes define additional methods on generic functions.

It is NOT intended that you do overloading.

Overloading is the practice of applying unrelated definitions to the same operator.

The idea behind generic functions is that you first define the "meaning" of the generic operation in terms of the signature its arguments will take. Then you define methods that implement this signature for a variety of types that all satisfy the meaning of the generic function.