[cdr-discuss] Names for the equality generic function

Christophe Rhodes csr21 at cantab.net
Thu Feb 17 11:53:26 UTC 2011


Pascal Costanza <pc at p-cos.net> writes:

> Once it's a generic function, turning it into a context-sensitive function is not so hard anymore:
>
> (defmethod equalp ((o1 my-class) (o2 my-class))
>   (case *my-context*
>     (do ...)
>     (di ...)
>     (da ...)
>     (otherwise ... default ...)))
>
> ...or with ContextL:
>
> (define-layered-function my-equalp (o1 o2)
>   (:method :in do (...) ...)
>   (:method :in di (...) ...)
>   (:method :in da (...) ...)
>   (:method (...) ... default ...))
>
> (defmethod equalp ((o1 my-class) (o2 my-class))
>   (my-equalp o1 o2))
>
> The generic function equalp ensures that your own comparison methods
> are more easily available to other third-party code, and that's the
> main purpose of making it generic.

That would be true if equalp only had one argument.  Since it has two,
the way in which it is made context-sensitive must be common between
classes potentially "owned" by different codebases, otherwise extensions
/ specializations won't compose.

Cheers,

Christophe




More information about the cdr-discuss mailing list