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

Re: Anonymous Generic Function Proposal (Draft 2)



Dick and I had a discussion about with-added-methods.  We came to the
following conclusion about handling Case 3.

(with-added-methods <generic-function> (<methods>*) . <body>)

This takes a generic function and a list of methods specified as
lambda-expressions, creates a copy of the generic function and extends
it by adding the given methods.  Within the lexical scope of the form,
(in <body>) appearances of <generic-function> refer to the extended
generic-function.  with-added-methods does not affect the original
definition of <generic-function>.

This answers my question --

    (defmethod fie (x) 0)

    (defun foo (x)
      (with-added-methods fie ((lambda ((x P1)) 17))
          (cons (fie x) (fum x)))

    (defun fum (y) (fie y))

    (foo (make-instance 'P1)) ==> (17 . 0)


And it answers Pavel's query:
    During the time that WITH-ADDED-METHODS is active, should the
    other processes see the added methods or not?  I would hope not!
Correct.

To obtain a special version of print with added methods, one uses
   (with-added-methods #'print ((lambda (...)...) (lambda (...)...))
      #'print)
and passes the returned generic function as an argument.  Note that
since the generic function is copied on entry, this specialized print is
not affected by later global changes to the print generic function.