[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


>    I think the default body of DEFINE-OPERATION will handle this for you, i.e.,
>            (define-operation (where-defined foo) nil)
>    will cause NIL to be returned if WHERE-DEFINED isn't defined.

I know about default methods.  Sorry, I guess I didn't state the problem
clearly enough since I got a couple of replies that basically said the same
thing.  I want to take an EXISTING operation 'foo' and write another one that
calls 'foo' if the object handles 'foo', but returns 'nil' (instead of
breaking) if the object does not handle 'foo'.  I used 'where-defined' as an
example, in which I wanted to define a NEW operation that behaved like
'where-defined' but returned 'nil' for, say, a read-table.

I could, of course, just redefine 'foo' but (a) I then lose whatever default
method 'foo' had, and (b) assuming 'foo' is part of a package/tool (or a T3
thing like 'where-defined'), it doesn't seem clean to redefine it (plus it
could possibly break with new versions of the package or even due to other
uses of that operation by the package that I didn't anticipate).  What I
would like is something like:

        (let ((package-foo (*value package-env 'foo)))
           (define-operation (foo x)
              ...use package-foo if possible...
              ...else use my default...))

rather than:

        (eval '(define-operation (foo x) ...) package-env)

-- Ashwin.