views:

139

answers:

1

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

+5  A: 

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
Cristian
To be clear 'foo is shorthand for (function foo) (which is the same as (quote foo) in elisp, but not in other lisp-2s like CL).
jrockway
#'my-function is lispier.
andrew