Does Common Lisp Object System (CLOS) support duck printing?

I read Practical General Lisp, and I wonder if Common Lisp supports Duck-Typing, such as Ruby?

In Ruby, you can call a method on an object, regardless of class, if it implements a method with a name and argument list that the caller expects.

What about CLOS? Is it possible to call methods on objects without examining their class, just assuming that a common function will handle it. Perhaps duck printing is not needed because CLOS does not follow a messaging philosophy, and methods are not class bound.

+4
source share
1 answer

Perhaps duck printing is not needed because CLOS does not follow a messaging philosophy, and methods are not class bound.

This is exactly the case. Each generic function can be dynamically specialized for a particular class. It can also be implemented by default. And since Lisp uses dynamic typing, each function can be called with arguments of any type, and for general functions, a dispatch solution based on the type of the argument is taken at run time.

+13
source

Source: https://habr.com/ru/post/1397099/


All Articles