lispelispsetf

Lisp: Find the setf way of doing the equivalent of fset


Find the setf way of doing the equivalent of fset in lisp.


Solution

  • (symbol-function 'foo) is a Generalized Variable in elisp, so you can use:

    (setf (symbol-function 'forward-word) #'backward-word)
    

    as an alternative to:

    (fset 'forward-word #'backward-word)
    

    (As a side-note, you can do the same thing with cl-letf as a replacement for the deprecated flet when you want to override a function using dynamic scope.)