[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return

From: Stephen J. Turnbull
Subject: Re: Return
Date: Wed, 08 Dec 2010 01:14:34 +0900

David Kastrup writes:
 > "Stephen J. Turnbull" <address@hidden> writes:

 > > (add-hook captain-hook (defun sm-or-dak?-style-foo () (foo bar baz)))

In view of David's reaction, it looks like

    (add-hook 'captain-hook (defun sm-style-foo () foo bar baz))

is a better guess, and fixes a syntax error in passing.

 >  > Eek.  No point in using the return value of a defun (is it even
 > defined?)  like that if you can equally well use the function symbol.

Better yet, use both, which is what that idiom does.  (defun returns
the defun'ed function symbol.)

(defun sm-style-foo () foo bar baz)
=> sm-style-foo

I use this in my init file in contexts like

(add-hook 'text-mode-hook
          ;; yes I know this function is already defined
          (defun auto-fill-mode-on () (auto-fill-mode 1)))

Note that the defun serves a real purpose here; it makes the init file
"just enough" idempotent in the face of changes to the hook function
being added.  If that were a lambda, not only would the definition of
the hook function be changed, but the original definition would remain
on the hook.

Embedding the defun in the argument might be considered excessively

reply via email to

[Prev in Thread] Current Thread [Next in Thread]