reddit / emacs

Learn how to temporary override function definitions

tonyaldon · 2022-12-07 20:32
JDRiverRun · 2022-12-08 02:07
The modern equivalent of `flet` is `(cl-letf ((symbol-function 'bar) (...))`.
tonyaldon · 2022-12-08 05:56
You are right. In fact if you read the source code of `flet`, you can see that this is what `flet` does using `letf` which is now aliased by `cl-letf`: (defmacro flet (bindings &rest body) ... `(letf ,(mapcar (lambda (x) ... (let ((func `(cl-function (lambda ,(cadr x) (cl-block ,(car x) ,@(cddr x)))))) ... (list `(symbol-function ',(car x)) func))) bindings) ,@body)) Thanks for sharing this way of temporary overriding a function definition without using an obsolete function. I will mention it in today's video ;)