Search code examples
lispcommon-lispclos

How to describe and implement and interface in common lisp


I am implementing a graph data structure that will store arbitrary objects as vertices. I want to define an interface for things like getting the key for an object so that all vertices can have a key. In my mind, this sounds like where I might use an interface in a language like java.

interface Vertex {
  String key (Vertex v);
  // etc...
}

How can I emulate the behaviour of an interface in common lisp?


Solution

  • As Rainer Joswig mentioned in the comments, there are no interfaces, in the sense that some languages use them (e.g., Java), so all you need to do is define some generic functions and optionally a mixin class to specify as a superclass of implementing classes.