Function: cl-flet
cl-flet is an autoloaded macro defined in cl-macs.el.gz.
Signature
(cl-flet ((FUNC ARGLIST BODY...) ...) FORM...)
Documentation
Make local function definitions.
Each definition can take the form (FUNC EXP) where FUNC is the function
name, and EXP is an expression that returns the function value to which
it should be bound, or it can take the more common form (FUNC ARGLIST
BODY...) which is a shorthand for (FUNC (lambda ARGLIST BODY))
where BODY is wrapped in a cl-block named FUNC.
FUNC is defined only within FORM, not BODY, so you can't write recursive
function definitions. Use cl-labels for that. See Info node
(cl) Function Bindings for details.
Probably introduced at or before Emacs version 24.3.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-macs.el.gz
;;;###autoload
(defmacro cl-flet (bindings &rest body)
"Make local function definitions.
Each definition can take the form (FUNC EXP) where FUNC is the function
name, and EXP is an expression that returns the function value to which
it should be bound, or it can take the more common form (FUNC ARGLIST
BODY...) which is a shorthand for (FUNC (lambda ARGLIST BODY))
where BODY is wrapped in a `cl-block' named FUNC.
FUNC is defined only within FORM, not BODY, so you can't write recursive
function definitions. Use `cl-labels' for that. See Info node
`(cl) Function Bindings' for details.
\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
(declare (indent 1)
;; The first (symbolp form) case doesn't use `&name' because
;; it's hard to associate this name with the body of the function
;; that `form' will return (bug#65344).
;; We could try and use a `&name' for those cases where the
;; body of the function can be found, (e.g. the form wraps
;; some `prog1/progn/let' around the final `lambda'), but it's
;; not clear it's worth the trouble.
(debug ((&rest [&or (symbolp form)
(&define [&name symbolp "@cl-flet@"]
[&name [] gensym] ;Make it unique!
cl-lambda-list
cl-declarations-or-string
[&optional ("interactive" interactive)]
def-body)])
cl-declarations body)))
(let ((binds ()) (newenv macroexpand-all-environment))
(dolist (binding bindings)
(let* ((var (make-symbol (format "--cl-%s--" (car binding))))
(args-and-body (cdr binding))
(args (car args-and-body))
(body (cdr args-and-body)))
(if (and (null body)
(macroexp-copyable-p args))
;; Optimize (cl-flet ((fun var)) body).
(setq var args)
(push (list var (if (null body)
args
(let ((parsed-body (macroexp-parse-body body)))
`(cl-function
(lambda ,args
,@(car parsed-body)
(cl-block ,(car binding)
,@(cdr parsed-body)))))))
binds))
(push (cons (car binding)
(lambda (&rest args)
(if (eq (car args) cl--labels-magic)
(list cl--labels-magic var)
`(funcall ,var ,@args))))
newenv)))
;; FIXME: Eliminate those functions which aren't referenced.
(macroexp-let* (nreverse binds)
(macroexpand-all
`(progn ,@body)
;; Don't override lexical-let's macro-expander.
(if (assq 'function newenv) newenv
(cons (cons 'function #'cl--labels-convert) newenv))))))