Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Common Lisp Object System (CLOS) support duck-typing?

I'm reading "Practical Common Lisp" and I wonder if Common Lisp supports Duck-Typing like e.g. Ruby?

In Ruby it's possible to call a method on an object regardless of the class as long as it implements a method with the name and argument list that the caller assumes.

What about CLOS? Is it possible to call methods on objects without considering their class simply by assuming that a generic function will cope with it. Perhaps duck-typing is not needed because CLOS doesn't follow a message passing philosophy and methods are not bound to classes.

like image 297
v_nomad Avatar asked Dec 10 '22 02:12

v_nomad


1 Answers

Perhaps duck-typing is not needed because CLOS doesn't follow a message passing philosophy and methods are not bound to classes.

That is exactly the case. Every generic function can be dynamically specialized for a certain class. There can also be a default implementation. And since Lisp uses dynamic typing, every function can be called with arguments of any type, and for generic functions the dispatch decision, based on the type of argument, is taken at runtime.

like image 178
Vsevolod Dyomkin Avatar answered May 10 '23 23:05

Vsevolod Dyomkin