I often want to write GFs with optional arguments, which I want to
default sensibly -- something like
step-thingy thing &optional (nsteps 1)
I obviously don't want to do this by having each method have its own
default value as this commits me either to a global variable for the
default, or a nightmare every time I change the default.
What I currently do is define an AROUND method on T (or some other
suitably broad class), which does something like:
(defmethod step-thingy :around (thing &optional (nsteps 1))
(call-next-method thing nsteps))
But this is kind of unsatisfactory because all the other methods then
have this optional argument which I know isn't really optional at
all.
I've also thought of having a wrapper function which does the
defaulting and then have the real GF not have optional arguments, but
that means I suddenly have two functions, both of which
really need to be visible -- one to call & one to add methods to.
Are there any better ways of doing this that I've missed?
--tim
Tim Bradshaw <···@aiai.ed.ac.uk> writes:
>
> I often want to write GFs with optional arguments, which I want to
> default sensibly -- something like...
> I've also thought of having a wrapper function which does the
> defaulting and then have the real GF not have optional arguments, but
> that means I suddenly have two functions, both of which
> really need to be visible -- one to call & one to add methods to.
This is exactly what you're asking for.
The function is a "shorthand" that is doing your global defaulting,
the method is the real computation that takes two arguments.
-Kelly Murray ···@franz.com
In article <···············@todday.aiai.ed.ac.uk>,
Tim Bradshaw <···@aiai.ed.ac.uk> wrote:
>I've also thought of having a wrapper function which does the
>defaulting and then have the real GF not have optional arguments, but
>that means I suddenly have two functions, both of which
>really need to be visible -- one to call & one to add methods to.
That's what I would do. It's not very different from the distinction
between DESCRIBE and DESCRIBE-OBJECT.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.