Function: cl--generic-make-function

cl--generic-make-function is a byte-compiled function defined in cl-generic.el.gz.

Signature

(cl--generic-make-function GENERIC)

Documentation

Return the function to put into the symbol-function of GENERIC.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-generic.el.gz
(defun cl--generic-make-function (generic)
  "Return the function to put into the `symbol-function' of GENERIC."
  ;; The function we want is the one that performs the dispatch,
  ;; but that function depends on the set of methods and needs to be
  ;; flushed/recomputed when the set of methods changes.
  ;; To avoid reconstructing such a method N times for N `cl-defmethod',
  ;; we construct the dispatch function lazily:
  ;; we first return a "lazy" function, which waits until the
  ;; first call to the method to really compute the dispatch function,
  ;; at which point we replace the dummy with the real one.
  (with-memoization (cl--generic-lazy-function generic)
    (lambda (&rest args)
      (let* ((real
              (cl--generic-make-next-function generic
                                              (cl--generic-dispatches generic)
                                              (cl--generic-method-table generic)))
             (sym (cl--generic-name generic))
             (old-adv-cc (get-advertised-calling-convention
                          (symbol-function sym))))
        (when (listp old-adv-cc)
          (set-advertised-calling-convention real old-adv-cc nil))
        (when (symbol-function sym)
          (let ((current-load-list nil))
            (defalias sym real)))
        (apply real args)))))