Search code examples
common-lispclosgeneric-function

Replacing an ordinary function with a generic function


I'd like to use names such as elt, nth and mapcar with a new data structure that I am prototyping, but these names designate ordinary functions and so, I think, would need to be redefined as generic functions.

Presumably it's bad form to redefine these names?

Is there a way to tell defgeneric not to generate a program error and to go ahead and replace the function binding?

Is there a good reason for these not being generic functions or is just historic?

What's the considered wisdom and best practice here please?


Solution

  • If you are using SBCL or ABCL, and aren't concerned with ANSI compliance, you could investigate Extensible Sequences:

    http://www.sbcl.org/manual/#Extensible-Sequences

    http://www.doc.gold.ac.uk/~mas01cr/papers/ilc2007/sequences-20070301.pdf

    ...you can't redefine functions in the COMMON-LISP package, but you could create a new package and shadow the imports of the functions you want to redefine.