Our example demonstrates how to define methods on struct types in Lisp using the Common Lisp Object System (CLOS).
To run the program:
In this Lisp example, we use CLOS to define a rect class and its methods. The area and perim methods are defined using the defmethod macro, which allows for method dispatch based on the class of its arguments.
Unlike Go, Lisp doesn’t have a concept of pointer vs. value receivers. All object parameters in Lisp are effectively passed by reference, so there’s no need to explicitly use pointers.
The main function demonstrates creating an instance of the rect class and calling its methods. In Lisp, we don’t need to distinguish between calling methods on values or pointers as we would in Go.
Next, we’ll look at Lisp’s mechanism for defining abstract interfaces and polymorphism: generic functions and method combinations.