method-versions
A Common Lisp library for dispatching generic methods based on the value of a global parameter rather than on one of the required parameters.

Homepage: http://nklein.com/software/method-versions/

This library is by Patrick Stein.

In this example, we do a silly form of internationalization. To that end, we will use English as the default language and define some other languages.

(method-versions:define-method-version latin) (method-versions:define-method-version pig-latin) (method-versions:define-method-version french latin) (method-versions:define-method-version spanish latin)

We will prepare a language parameter and a welcome method that is versioned on the language.

(declaim (special *language*)) (defparameter *language* nil) (defgeneric welcome () (:method-combination method-versions:method-version-method-combination *language*))

And, we define welcome methods for the various languages (accidentally forgetting spanish).

(defmethod welcome () :welcome) (defmethod welcome :latin () :velkominum) (defmethod welcome :pig-latin () :elcomeway) (defmethod welcome :french () :bonjour)

Then, we will try each of the languages in turn.

(mapcar #'(lambda (ll) (let ((*language* ll)) (welcome))) '(nil :latin :pig-latin :french :spanish)) => (:welcome :velkominum :elcomeway :bonjour :velkominum)

clos language extension