Defining Methods


(defmacro defmethod (selector args rest rest)
  `(defmethod-expr (quote ,selector)
       (quote ,args) (quote ,rest)))

(defun defmethod-expr (selector args rest)
  (let (class fnname)
    (unless (and (consp (car args))
                 (setq class (cadar args))
                 (symbolp class))
      (error "Bad form - no class name ~S" args))
    (setq fnname (intern
      (concatenate 'string (symbol-name class)
                   "-" (symbol-name selector))))
    (pushnew (list selector fnname)
             (get class 'methods))
    (eval (cons 'defun (cons fnname
      (cons (mapcar #'(lambda (x)
                       (if (consp x) (car x) x))
                    args)
            rest)))) ))

Contents    Page-10    Prev    Next    Page+10    Index