[Top][All Lists]

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

Re: help with c-mode-common-hook

From: Kai Grossjohann
Subject: Re: help with c-mode-common-hook
Date: Thu, 03 May 2007 17:42:48 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.97 (gnu/linux)

Hadron <address@hidden> writes:

> Kai Grossjohann <address@hidden> writes:
>> Hadron <address@hidden> writes:
>>> I'm not sure what ellided means. But how come it works in my direct
>>> add-hook then? The "old" way was working before (famous last words :-;).
>> The "direct" method works because you have different code in that
>> case.
>> To make the "direct" method fail, you need to do this:
>> (add-hook 'c-mode-common-hook 
>>           (lambda ()
>>             (lambda ()
>>               ...same code as before)))
>> As you can see, there is one lambda too many.
> But there wasnt 2 lambdas in my other way:
> | (defun my-compile ()
> |   (message "in my-compile")
> |   (lambda () [...]
> |   )
> Am I missing something glaringly obvious here?

defun has an implicit lambda -- sorry if that wasn't clear.  Perhaps I
explain it with Scheme (Pidgin Scheme, I haven't used actual Scheme
for at least 15 years) first:

(define (foo) ...) is the same as (setq foo (lambda () ...)).  Thus,
(define (foo) (lambda () ...)) is the same as (setq foo (lambda ()
(lambda () ...))).

In Emacs Lisp, it looks less symmetric:

(defun foo () ...) is the same as (fset foo (lambda() ...)).  Thus,
(defun foo () (lambda () ...)) is the same as (fset foo (lambda ()
(lambda () ...))).

To be concrete: my-compile is a function that, when called, does the
following: first, it prints something.  Then it returns a function.
The function it returns would, if it were ever called, do useful
things.  However, it is never called -- the return value of my-compile
is discarded (when my-compile is added to a hook and then the hook is


reply via email to

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