Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should `flet` be replaced with `cl-flet` or `cl-letf` ?

Tags:

emacs

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?

like image 717
ironsand Avatar asked Sep 19 '13 13:09

ironsand


1 Answers

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.

Small example when 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.

like image 95
abo-abo Avatar answered Oct 12 '22 19:10

abo-abo