How do I pass a function as a parameter in Emacs Lisp?

emacs, variables

Solution

I figured it out. It's pretty simple. Just quote the function:

Fixed code: (defun my-function () ;; do my stuff)

(add-hook 'some-hook-list 'my-function) ;;; There's a quote before my-function

Problem

I'm trying to add a function I created to a hook, but the obvious (to my Schemer mind) way doesn't seem to work. The function is used in 2 places and I want to keep my code DRY so no anonymous function. Though I could wrap my function in a lambda, there must be a better way. Doesn't work: ``` (defun my-function () ;; do my stuff) (add-hook 'some-hook-list my-function) ``` I get the error message: Symbol's value as variable is void: my-function

Original source