[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
generic function
Date: Sun, 21 Jul 1991 05:35 EDT
From: barmar@Think.COM (Barry Margolin)
Date: Mon, 22 Jul 1991 08:27 EDT
From: smith@icat.larc.nasa.gov (Steven L. Smith)
Is there way to define a generic function which will specialize
based on the number of arguments passed. For example, I'm trying
to do the following:
Neither Flavors nor CLOS support this; all generic function dispatch is
based on types or equality. Maybe it's possible to do it in CLOS by
using the meta-object protocol to define a new class of generic
functions that implements a different kind of dispatching.
Although the general problem is often quite easily solved without
meta-objects by just re-casting the problem description to involve a
second function, which makes the number of arguments into something that
can be dispatched off of:
(DEFUN FN1 (&REST ARGS) (APPLY #'FN2 (LENGTH ARGS) ARGS))
(DEFGENERIC FN2 (N ...other args...) ...)
The original discussion was about specializing FN1, but if you don't
mind dispatching on FN2 instead, this solution works nicely.
Note that a similar solution has occurred in CLOS with the way DESCRIBE
and DESCRIBE-OBJECT are handled. DESCRIBE is the function the user
calls, but DESCRIBE-OBJECT is the thing you customize.