Some elisp functions that I have installed generate warnings:
`flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
Is it dangerous if I simply replace all flet with cl-flet?
If it is OK to replace them, which one is better?
If it is not dangerous to replace it, I'd send pull requests to the projects.
Is there some reason that they don't change it?
flet isn't the same as either cl-flet or cl-letf.
It's more dangerous (and maybe more powerful). That's why it's being deprecated.
Since it's different (binds dynamically a function name), you have to think
in each case if it's appropriate to replace it with cl-flet.
flet can't be replaced with cl-flet
(defun adder (a b)
(+ a b))
(defun add-bunch (&rest lst)
(reduce #'adder lst))
(add-bunch 1 2 3 4)
;; 10
(flet ((adder (a b) (* a b)))
(add-bunch 1 2 3 4))
;; 24
(cl-flet ((adder (a b) (* a b)))
(add-bunch 1 2 3 4))
;; 10
Note that cl-flet does lexical binding, so the behavior of adder isn't changed,
while flet does dynamic binding, which makes add-bunch temporarily produce a factorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With