unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* elisp macros problem
@ 2004-07-24 18:39 Lowell Kirsh
  2004-07-24 19:00 ` David Kastrup
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-24 18:39 UTC (permalink / raw)


I am defining an emacs lisp macro to do:

(my-add-hook 'lisp
    ...)

which should give:

(add-hook 'lisp-mode-hook
   (lambda () ...))

I have:

(defmacro my-add-hook (hook &rest body)
   (let ((tempvar (make-symbol "cat")))
     `(flet ((,tempvar (sym str)
                       (make-symbol (concat (symbol-name sym) str))))
        (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))

Does anyone know what's wrong with this and why it doesn't work?

Lowell

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 18:39 elisp macros problem Lowell Kirsh
@ 2004-07-24 19:00 ` David Kastrup
  2004-07-24 22:08   ` Lowell Kirsh
  2004-07-24 19:15 ` Barry Margolin
  2004-07-26  1:35 ` Lowell Kirsh
  2 siblings, 1 reply; 33+ messages in thread
From: David Kastrup @ 2004-07-24 19:00 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> I am defining an emacs lisp macro to do:
> 
> (my-add-hook 'lisp
>     ...)
> 
> which should give:
> 
> (add-hook 'lisp-mode-hook
>    (lambda () ...))
> 
> I have:
> 
> (defmacro my-add-hook (hook &rest body)
>    (let ((tempvar (make-symbol "cat")))
>      `(flet ((,tempvar (sym str)
>                        (make-symbol (concat (symbol-name sym) str))))
>         (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))
> 
> Does anyone know what's wrong with this and why it doesn't work?

I don't know where to start...

First of all, your use of flet is complete nonsense.  You flet an
uninterned symbol with the name "cat" to some function.  However, you
never use that function.  Instead you are trying to call the interned
symbol "cat" (which is probably undefined).  Even if one fixed that,
it is completely unnecessary.  Just do

(defmacro my-add-hook (hook &rest body)
  `(add-hook ',(intern (concat (symbol-name hook) "-mode-hook"))
        (lambda () ,@body)))

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 18:39 elisp macros problem Lowell Kirsh
  2004-07-24 19:00 ` David Kastrup
@ 2004-07-24 19:15 ` Barry Margolin
  2004-07-24 19:59   ` Pascal Bourguignon
  2004-07-26  1:35 ` Lowell Kirsh
  2 siblings, 1 reply; 33+ messages in thread
From: Barry Margolin @ 2004-07-24 19:15 UTC (permalink / raw)


In article <cduad9$7tg$1@mughi.cs.ubc.ca>,
 Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:

> I am defining an emacs lisp macro to do:
> 
> (my-add-hook 'lisp
>     ...)
> 
> which should give:
> 
> (add-hook 'lisp-mode-hook
>    (lambda () ...))
> 
> I have:
> 
> (defmacro my-add-hook (hook &rest body)
>    (let ((tempvar (make-symbol "cat")))
>      `(flet ((,tempvar (sym str)
>                        (make-symbol (concat (symbol-name sym) str))))
>         (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))
> 
> Does anyone know what's wrong with this and why it doesn't work?

You need to use ,tempvar in place of cat in the last line.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 19:15 ` Barry Margolin
@ 2004-07-24 19:59   ` Pascal Bourguignon
  2004-07-24 20:50     ` David Kastrup
  0 siblings, 1 reply; 33+ messages in thread
From: Pascal Bourguignon @ 2004-07-24 19:59 UTC (permalink / raw)


Barry Margolin <barmar@alum.mit.edu> writes:

> In article <cduad9$7tg$1@mughi.cs.ubc.ca>,
>  Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
> 
> > I am defining an emacs lisp macro to do:
> > 
> > (my-add-hook 'lisp
> >     ...)
> > 
> > which should give:
> > 
> > (add-hook 'lisp-mode-hook
> >    (lambda () ...))
> > 
> > I have:
> > 
> > (defmacro my-add-hook (hook &rest body)
> >    (let ((tempvar (make-symbol "cat")))
> >      `(flet ((,tempvar (sym str)
> >                        (make-symbol (concat (symbol-name sym) str))))
> >         (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))
> > 
> > Does anyone know what's wrong with this and why it doesn't work?
> 
> You need to use ,tempvar in place of cat in the last line.

Then, (not (eq (make-symbol "toto")(make-symbol "toto"))), even on emacs lisp.
You should use intern!


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 19:59   ` Pascal Bourguignon
@ 2004-07-24 20:50     ` David Kastrup
  2004-07-24 21:49       ` Lowell Kirsh
  0 siblings, 1 reply; 33+ messages in thread
From: David Kastrup @ 2004-07-24 20:50 UTC (permalink / raw)


Pascal Bourguignon <spam@thalassa.informatimago.com> writes:

> Barry Margolin <barmar@alum.mit.edu> writes:
> 
> > In article <cduad9$7tg$1@mughi.cs.ubc.ca>,
> >  Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
> > 
> > > (defmacro my-add-hook (hook &rest body)
> > >    (let ((tempvar (make-symbol "cat")))
> > >      `(flet ((,tempvar (sym str)
> > >                        (make-symbol (concat (symbol-name sym) str))))
> > >         (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))
> > > 
> > > Does anyone know what's wrong with this and why it doesn't work?
> > 
> > You need to use ,tempvar in place of cat in the last line.
> 
> Then, (not (eq (make-symbol "toto")(make-symbol "toto"))), even on
> emacs lisp.  You should use intern!

For accessing xxx-mode-hook, yes.  But for the "cat" thingy, ,tempvar
would be ok, even though pretty pointless: one does not really need to
bind a function here.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 20:50     ` David Kastrup
@ 2004-07-24 21:49       ` Lowell Kirsh
  0 siblings, 0 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-24 21:49 UTC (permalink / raw)


Thanks all. I now see how pointless cat was, but the reason it was there 
in the first place was because i had made it a separate function (for 
testing).

cheers,
Lowell

David Kastrup wrote:
> Pascal Bourguignon <spam@thalassa.informatimago.com> writes:
> 
> 
>>Barry Margolin <barmar@alum.mit.edu> writes:
>>
>>
>>>In article <cduad9$7tg$1@mughi.cs.ubc.ca>,
>>> Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
>>>
>>>
>>>>(defmacro my-add-hook (hook &rest body)
>>>>   (let ((tempvar (make-symbol "cat")))
>>>>     `(flet ((,tempvar (sym str)
>>>>                       (make-symbol (concat (symbol-name sym) str))))
>>>>        (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))
>>>>
>>>>Does anyone know what's wrong with this and why it doesn't work?
>>>
>>>You need to use ,tempvar in place of cat in the last line.
>>
>>Then, (not (eq (make-symbol "toto")(make-symbol "toto"))), even on
>>emacs lisp.  You should use intern!
> 
> 
> For accessing xxx-mode-hook, yes.  But for the "cat" thingy, ,tempvar
> would be ok, even though pretty pointless: one does not really need to
> bind a function here.
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 19:00 ` David Kastrup
@ 2004-07-24 22:08   ` Lowell Kirsh
  2004-07-24 23:41     ` David Kastrup
  0 siblings, 1 reply; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-24 22:08 UTC (permalink / raw)



 > (defmacro my-add-hook (hook &rest body)
 >   `(add-hook ',(intern (concat (symbol-name hook) "-mode-hook"))
 >         (lambda () ,@body)))
 >

I just tried it out and it doesn't seem to work. I tried both:

(my-add-hook 'emacs-lisp (keyboard-translate ?\( ?\[))
              ^
and

(my-add-hook emacs-lisp (keyboard-translate ?\( ?\[))


Lowell

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 22:08   ` Lowell Kirsh
@ 2004-07-24 23:41     ` David Kastrup
  2004-07-25  1:58       ` Lowell Kirsh
  0 siblings, 1 reply; 33+ messages in thread
From: David Kastrup @ 2004-07-24 23:41 UTC (permalink / raw)



Please don't copy me with Email to Usenet articles: it is a very bad
breach of netiquette to force the unwary to reply twice, once in
private and then again in public.

Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

>  > (defmacro my-add-hook (hook &rest body)
>  >   `(add-hook ',(intern (concat (symbol-name hook) "-mode-hook"))
>  >         (lambda () ,@body)))
>  >
> 
> I just tried it out and it doesn't seem to work. I tried both:
> 
> (my-add-hook 'emacs-lisp (keyboard-translate ?\( ?\[))
>               ^

Which is wrong.

> and
> 
> (my-add-hook emacs-lisp (keyboard-translate ?\( ?\[))

Which results here in:

emacs-lisp-mode-hook's value is 
((lambda nil
   (keyboard-translate 40 91)))


Hook run when entering Emacs Lisp mode.

You can customize this variable.

Defined in `emacs-lisp/lisp-mode'.

[back]

Looks fine to me.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 23:41     ` David Kastrup
@ 2004-07-25  1:58       ` Lowell Kirsh
  2004-07-25 10:59         ` Kalle Olavi Niemitalo
  0 siblings, 1 reply; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-25  1:58 UTC (permalink / raw)


sorry bout the bad etiquette. also, it turns out that it does seem to 
work. the reason that i didn't realize it was working was that i thought 
you could (add-hook 'some-mode ...) more than once, but really, this 
will just overwrite the previously added hook.

lowell

David Kastrup wrote:
> Please don't copy me with Email to Usenet articles: it is a very bad
> breach of netiquette to force the unwary to reply twice, once in
> private and then again in public.
> 
> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
> 
> 
>> > (defmacro my-add-hook (hook &rest body)
>> >   `(add-hook ',(intern (concat (symbol-name hook) "-mode-hook"))
>> >         (lambda () ,@body)))
>> >
>>
>>I just tried it out and it doesn't seem to work. I tried both:
>>
>>(my-add-hook 'emacs-lisp (keyboard-translate ?\( ?\[))
>>              ^
> 
> 
> Which is wrong.
> 
> 
>>and
>>
>>(my-add-hook emacs-lisp (keyboard-translate ?\( ?\[))
> 
> 
> Which results here in:
> 
> emacs-lisp-mode-hook's value is 
> ((lambda nil
>    (keyboard-translate 40 91)))
> 
> 
> Hook run when entering Emacs Lisp mode.
> 
> You can customize this variable.
> 
> Defined in `emacs-lisp/lisp-mode'.
> 
> [back]
> 
> Looks fine to me.
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-25  1:58       ` Lowell Kirsh
@ 2004-07-25 10:59         ` Kalle Olavi Niemitalo
  0 siblings, 0 replies; 33+ messages in thread
From: Kalle Olavi Niemitalo @ 2004-07-25 10:59 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> the reason that i didn't realize it was working was that i
> thought you could (add-hook 'some-mode ...) more than once, but
> really, this will just overwrite the previously added hook.

No, it won't.

(setq sample-hook '())
(add-hook 'sample-hook 'sample-1)
(add-hook 'sample-hook 'sample-2)
(add-hook 'sample-hook 'sample-2)

After these forms, the value of sample-hook is (sample-2 sample-1).
The second add-hook did not overwrite the first one.
However, the third one had no effect, because sample-2 was
already in the hook.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-24 18:39 elisp macros problem Lowell Kirsh
  2004-07-24 19:00 ` David Kastrup
  2004-07-24 19:15 ` Barry Margolin
@ 2004-07-26  1:35 ` Lowell Kirsh
  2004-07-26  1:55   ` Rahul Jain
                     ` (2 more replies)
  2 siblings, 3 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-26  1:35 UTC (permalink / raw)


Why does this not work:

(defmacro my-add-hooks (hooks &rest body)
   `(dolist (hook ,hooks)
       (my-add-hook hook ,@body)))

??

Lowell

Lowell Kirsh wrote:
> I am defining an emacs lisp macro to do:
> 
> (my-add-hook 'lisp
>    ...)
> 
> which should give:
> 
> (add-hook 'lisp-mode-hook
>   (lambda () ...))
> 
> I have:
> 
> (defmacro my-add-hook (hook &rest body)
>   (let ((tempvar (make-symbol "cat")))
>     `(flet ((,tempvar (sym str)
>                       (make-symbol (concat (symbol-name sym) str))))
>        (add-hook (cat ,hook "-mode-hook") (lambda () ,@body)))))
> 
> Does anyone know what's wrong with this and why it doesn't work?
> 
> Lowell

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  1:35 ` Lowell Kirsh
@ 2004-07-26  1:55   ` Rahul Jain
  2004-07-26  2:53     ` Lowell Kirsh
  2004-07-26  2:54     ` Lowell Kirsh
  2004-07-26  2:03   ` Barry Margolin
  2004-07-26  5:55   ` David Kastrup
  2 siblings, 2 replies; 33+ messages in thread
From: Rahul Jain @ 2004-07-26  1:55 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> Why does this not work:
>
> (defmacro my-add-hooks (hooks &rest body)
>    `(dolist (hook ,hooks)
>        (my-add-hook hook ,@body)))
>
> ??

It does. In fact, every possible string of characters works as it's
supposed to.

You probably mean "why does this not do X?" but you never tell us what X
is, so we don't know how to help you achieve that.

Hint: you might want to macroexpand-1 a sample usage of the macro and
see if it expands to what you desired.

According to your definition:
(my-add-hooks '(lisp-mode-hook emacs-lisp-mode-hook)
  ...)
<=>
(dolist (hook '(lisp-mode-hook emacs-lisp-mode-hook))
  (my-add-hook hook ...))

Is that what you wanted?

-- 
Rahul Jain
rjain@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  1:35 ` Lowell Kirsh
  2004-07-26  1:55   ` Rahul Jain
@ 2004-07-26  2:03   ` Barry Margolin
  2004-07-26  3:06     ` Lowell Kirsh
  2004-07-26  5:55   ` David Kastrup
  2 siblings, 1 reply; 33+ messages in thread
From: Barry Margolin @ 2004-07-26  2:03 UTC (permalink / raw)


In article <ce1n4n$2gt$1@mughi.cs.ubc.ca>,
 Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:

> Why does this not work:
> 
> (defmacro my-add-hooks (hooks &rest body)
>    `(dolist (hook ,hooks)
>        (my-add-hook hook ,@body)))
> 
> ??

It looks like it should work to me.  Make sure you quote the list of 
hooks when calling it, e.g.

(my-add-hooks '(emacs-lisp lisp) (local-set-key ...))

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  1:55   ` Rahul Jain
@ 2004-07-26  2:53     ` Lowell Kirsh
  2004-07-26  4:05       ` Pascal Bourguignon
  2004-07-26  2:54     ` Lowell Kirsh
  1 sibling, 1 reply; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-26  2:53 UTC (permalink / raw)




Rahul Jain wrote:
> You probably mean "why does this not do X?" but you never tell us what X
> is, so we don't know how to help you achieve that.

What I meant was why does this not do the obvoious thing I want it to do...

> Hint: you might want to macroexpand-1 a sample usage of the macro and
> see if it expands to what you desired.
> 
> According to your definition:
> (my-add-hooks '(lisp-mode-hook emacs-lisp-mode-hook)
>   ...)
> <=>
> (dolist (hook '(lisp-mode-hook emacs-lisp-mode-hook))
>   (my-add-hook hook ...))
> 
> Is that what you wanted?

Almost. The call should actually be

(my-add-hooks '(lisp emacs-lisp)
    ...)

And yes, that is what I wanted.

Lowell

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  1:55   ` Rahul Jain
  2004-07-26  2:53     ` Lowell Kirsh
@ 2004-07-26  2:54     ` Lowell Kirsh
  2004-07-26 22:16       ` Kalle Olavi Niemitalo
  2004-07-26 22:58       ` Kevin Rodgers
  1 sibling, 2 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-26  2:54 UTC (permalink / raw)


btw, I can't find macroexpand-1. Does it exist in elisp?

Rahul Jain wrote:
> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
> 
> 
>>Why does this not work:
>>
>>(defmacro my-add-hooks (hooks &rest body)
>>   `(dolist (hook ,hooks)
>>       (my-add-hook hook ,@body)))
>>
>>??
> 
> 
> It does. In fact, every possible string of characters works as it's
> supposed to.
> 
> You probably mean "why does this not do X?" but you never tell us what X
> is, so we don't know how to help you achieve that.
> 
> Hint: you might want to macroexpand-1 a sample usage of the macro and
> see if it expands to what you desired.
> 
> According to your definition:
> (my-add-hooks '(lisp-mode-hook emacs-lisp-mode-hook)
>   ...)
> <=>
> (dolist (hook '(lisp-mode-hook emacs-lisp-mode-hook))
>   (my-add-hook hook ...))
> 
> Is that what you wanted?
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  2:03   ` Barry Margolin
@ 2004-07-26  3:06     ` Lowell Kirsh
  2004-07-26  4:49       ` Barry Margolin
  2004-07-26  6:10       ` Oliver Scholz
  0 siblings, 2 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-26  3:06 UTC (permalink / raw)


Yes, I have been making sure to quote the list, but it doesn't seem to 
work at all. I've also tried to macroexpand the forms I'm evaluating but 
the minibuffer just shows a condensed version of the expansion with lots 
of '...' placeholders. Is there a simple way to macroexpand and pretty 
print a form without the '...'s ?

Lowell

Barry Margolin wrote:
> In article <ce1n4n$2gt$1@mughi.cs.ubc.ca>,
>  Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
> 
> 
>>Why does this not work:
>>
>>(defmacro my-add-hooks (hooks &rest body)
>>   `(dolist (hook ,hooks)
>>       (my-add-hook hook ,@body)))
>>
>>??
> 
> 
> It looks like it should work to me.  Make sure you quote the list of 
> hooks when calling it, e.g.
> 
> (my-add-hooks '(emacs-lisp lisp) (local-set-key ...))
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  2:53     ` Lowell Kirsh
@ 2004-07-26  4:05       ` Pascal Bourguignon
  2004-07-26  4:13         ` Lowell Kirsh
  0 siblings, 1 reply; 33+ messages in thread
From: Pascal Bourguignon @ 2004-07-26  4:05 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> Rahul Jain wrote:
> > You probably mean "why does this not do X?" but you never tell us what X
> > is, so we don't know how to help you achieve that.
> 
> What I meant was why does this not do the obvoious thing I want it to do...

Perhaps because telepathic computers have not been invented yet?

Erase that. Perhaps because telepathic computers are not on the shelf items 
yet, and you don't work for the US Air Force, therefore you don't have one?


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  4:05       ` Pascal Bourguignon
@ 2004-07-26  4:13         ` Lowell Kirsh
  0 siblings, 0 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-26  4:13 UTC (permalink / raw)


ok, ok. it seemed obvious to me but i guess it wasn't. i concede.

Pascal Bourguignon wrote:

> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
> 
> 
>>Rahul Jain wrote:
>>
>>>You probably mean "why does this not do X?" but you never tell us what X
>>>is, so we don't know how to help you achieve that.
>>
>>What I meant was why does this not do the obvoious thing I want it to do...
> 
> 
> Perhaps because telepathic computers have not been invented yet?
> 
> Erase that. Perhaps because telepathic computers are not on the shelf items 
> yet, and you don't work for the US Air Force, therefore you don't have one?
> 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  3:06     ` Lowell Kirsh
@ 2004-07-26  4:49       ` Barry Margolin
  2004-07-26  5:20         ` Pascal Bourguignon
  2004-07-26  6:10       ` Oliver Scholz
  1 sibling, 1 reply; 33+ messages in thread
From: Barry Margolin @ 2004-07-26  4:49 UTC (permalink / raw)


In article <ce1sfo$3ol$1@mughi.cs.ubc.ca>,
 Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:

> Yes, I have been making sure to quote the list, but it doesn't seem to 
> work at all. I've also tried to macroexpand the forms I'm evaluating but 
> the minibuffer just shows a condensed version of the expansion with lots 
> of '...' placeholders. Is there a simple way to macroexpand and pretty 
> print a form without the '...'s ?

Use the *scratch* buffer for a better interface to the Emacs Lisp R-E-P 
loop.

> 
> Lowell
> 
> Barry Margolin wrote:
> > In article <ce1n4n$2gt$1@mughi.cs.ubc.ca>,
> >  Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
> > 
> > 
> >>Why does this not work:
> >>
> >>(defmacro my-add-hooks (hooks &rest body)
> >>   `(dolist (hook ,hooks)
> >>       (my-add-hook hook ,@body)))
> >>
> >>??
> > 
> > 
> > It looks like it should work to me.  Make sure you quote the list of 
> > hooks when calling it, e.g.
> > 
> > (my-add-hooks '(emacs-lisp lisp) (local-set-key ...))
> >

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  4:49       ` Barry Margolin
@ 2004-07-26  5:20         ` Pascal Bourguignon
  0 siblings, 0 replies; 33+ messages in thread
From: Pascal Bourguignon @ 2004-07-26  5:20 UTC (permalink / raw)


Barry Margolin <barmar@alum.mit.edu> writes:

> In article <ce1sfo$3ol$1@mughi.cs.ubc.ca>,
>  Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
> 
> > Yes, I have been making sure to quote the list, but it doesn't seem to 
> > work at all. I've also tried to macroexpand the forms I'm evaluating but 
> > the minibuffer just shows a condensed version of the expansion with lots 
> > of '...' placeholders. Is there a simple way to macroexpand and pretty 
> > print a form without the '...'s ?
> 
> Use the *scratch* buffer for a better interface to the Emacs Lisp R-E-P 
> loop.

Or any elisp buffer, with: C-u C-x C-e:

(macroexpand '(push 'a a)) C-u C-x C-e --> (setq a (cons (quote a) a))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  1:35 ` Lowell Kirsh
  2004-07-26  1:55   ` Rahul Jain
  2004-07-26  2:03   ` Barry Margolin
@ 2004-07-26  5:55   ` David Kastrup
  2004-07-27  6:38     ` Lowell Kirsh
  2004-07-27  6:54     ` Lowell Kirsh
  2 siblings, 2 replies; 33+ messages in thread
From: David Kastrup @ 2004-07-26  5:55 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> Why does this not work:
> 
> (defmacro my-add-hooks (hooks &rest body)
>    `(dolist (hook ,hooks)
>        (my-add-hook hook ,@body)))
> 
> ??

Because you need to write
`(dolist (hook ',hooks)

and then call this with an _unquoted_ list, like
(my-add-hooks (lisp emacs-lisp)
  body)

Apart from that, I consider this sort of thing a crock.  What are you
hoping to achieve that you would not be better off doing by a proper
function instead of a macro?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  3:06     ` Lowell Kirsh
  2004-07-26  4:49       ` Barry Margolin
@ 2004-07-26  6:10       ` Oliver Scholz
  1 sibling, 0 replies; 33+ messages in thread
From: Oliver Scholz @ 2004-07-26  6:10 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

[...]
> Is there a simple way to macroexpand and pretty print a form without
> the '...'s ?
[...]

I use M-x ielm for that.

    Oliver
-- 
9 Thermidor an 212 de la Révolution
Liberté, Egalité, Fraternité!

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  2:54     ` Lowell Kirsh
@ 2004-07-26 22:16       ` Kalle Olavi Niemitalo
  2004-07-26 22:58       ` Kevin Rodgers
  1 sibling, 0 replies; 33+ messages in thread
From: Kalle Olavi Niemitalo @ 2004-07-26 22:16 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> btw, I can't find macroexpand-1. Does it exist in elisp?

No, it doesn't.  It can be implemented in elisp but not easily.
There are several tricky cases, such as autoloaded macros, or
global aliases that refer to lexical macros.

http://paste.lisp.org/display/1684

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  2:54     ` Lowell Kirsh
  2004-07-26 22:16       ` Kalle Olavi Niemitalo
@ 2004-07-26 22:58       ` Kevin Rodgers
  1 sibling, 0 replies; 33+ messages in thread
From: Kevin Rodgers @ 2004-07-26 22:58 UTC (permalink / raw)


[Please don't top-post.]

Lowell Kirsh wrote:
 > btw, I can't find macroexpand-1. Does it exist in elisp?

Just use macroexpand.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  5:55   ` David Kastrup
@ 2004-07-27  6:38     ` Lowell Kirsh
  2004-07-27  6:54     ` Lowell Kirsh
  1 sibling, 0 replies; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-27  6:38 UTC (permalink / raw)


A crock? Now that I've got that macrology out of the way, does not

(my-add-hooks (emacs-lisp lisp lisp-interaction)
   (fun foo))

look better than

(add-hook 'emacs-lisp-mode-hook
    (lambda () (fun foo)))

(add-hook 'lisp-mode-hook
    (lambda () (fun foo)))

(add-hook ....


I think it does :)

Lowell

David Kastrup wrote:

> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
> 
> 
>>Why does this not work:
>>
>>(defmacro my-add-hooks (hooks &rest body)
>>   `(dolist (hook ,hooks)
>>       (my-add-hook hook ,@body)))
>>
>>??
> 
> 
> Because you need to write
> `(dolist (hook ',hooks)
> 
> and then call this with an _unquoted_ list, like
> (my-add-hooks (lisp emacs-lisp)
>   body)
> 
> Apart from that, I consider this sort of thing a crock.  What are you
> hoping to achieve that you would not be better off doing by a proper
> function instead of a macro?
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-26  5:55   ` David Kastrup
  2004-07-27  6:38     ` Lowell Kirsh
@ 2004-07-27  6:54     ` Lowell Kirsh
  2004-07-27  7:14       ` David Kastrup
  1 sibling, 1 reply; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-27  6:54 UTC (permalink / raw)


This still doesn't seem to work. With the following defun and call:

(defmacro my-add-hooks (hooks &rest body)
   `(dolist (hook ',hooks)
      (my-add-hook hook ,@body)))

(my-add-hooks (inferior-lisp lisp emacs-lisp lisp-interaction)
               (imenu-add-to-menubar "Symbols"))

I get the following macroexpansion, which looks correct to me, but 
doesn't actually do anything:

(cl-block-wrapper
  (catch (quote --cl-block-nil--)
    (let ((--dolist-temp--20870 (quote (inferior-lisp lisp emacs-lisp 
lisp-interaction)))
          hook)
      (while --dolist-temp--20870
        (setq hook (car --dolist-temp--20870))
        (my-add-hook hook
                     (imenu-add-to-menubar "Symbols"))
        (setq --dolist-temp--20870 (cdr --dolist-temp--20870)))
      nil)))


Lowell


David Kastrup wrote:

> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
> 
> 
>>Why does this not work:
>>
>>(defmacro my-add-hooks (hooks &rest body)
>>   `(dolist (hook ,hooks)
>>       (my-add-hook hook ,@body)))
>>
>>??
> 
> 
> Because you need to write
> `(dolist (hook ',hooks)
> 
> and then call this with an _unquoted_ list, like
> (my-add-hooks (lisp emacs-lisp)
>   body)
> 
> Apart from that, I consider this sort of thing a crock.  What are you
> hoping to achieve that you would not be better off doing by a proper
> function instead of a macro?
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-27  6:54     ` Lowell Kirsh
@ 2004-07-27  7:14       ` David Kastrup
  2004-07-27  8:10         ` Lowell Kirsh
  2004-07-27 23:22         ` Barry Fishman
  0 siblings, 2 replies; 33+ messages in thread
From: David Kastrup @ 2004-07-27  7:14 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> This still doesn't seem to work. With the following defun and call:
> 
> (defmacro my-add-hooks (hooks &rest body)
>    `(dolist (hook ',hooks)
>       (my-add-hook hook ,@body)))
> 
> (my-add-hooks (inferior-lisp lisp emacs-lisp lisp-interaction)
>                (imenu-add-to-menubar "Symbols"))
> 
> I get the following macroexpansion, which looks correct to me, but
> doesn't actually do anything:
> 
> (cl-block-wrapper
>   (catch (quote --cl-block-nil--)
>     (let ((--dolist-temp--20870 (quote (inferior-lisp lisp emacs-lisp
>     lisp-interaction)))
>           hook)
>       (while --dolist-temp--20870
>         (setq hook (car --dolist-temp--20870))
>         (my-add-hook hook
>                      (imenu-add-to-menubar "Symbols"))
>         (setq --dolist-temp--20870 (cdr --dolist-temp--20870)))
>       nil)))

That's because my-add-hook is a macro, too, and so you just add stuff
to hook-mode-hook three times.

> > Apart from that, I consider this sort of thing a crock.  What are
> > you hoping to achieve that you would not be better off doing by a
> > proper function instead of a macro?

In short, I still consider this sort of thing a crock, since you'd be
better off using a function instead of a macro.  You are unable to
comprehend what your macros do, and it shows.  Macros are just not
sensible for this sort of thing.  Use functions instead.  You'll need
to use some quotes at the outer level, but you'll understand what
happens.

To fix the above, you'd need to write something like

(defmacro my-add-hooks (hooks &rest body)
   (dolist (hook hooks)
      `(my-add-hook ,hook ,@body)))


-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-27  7:14       ` David Kastrup
@ 2004-07-27  8:10         ` Lowell Kirsh
  2004-07-27 12:05           ` Pascal Bourguignon
  2004-07-27 23:22         ` Barry Fishman
  1 sibling, 1 reply; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-27  8:10 UTC (permalink / raw)


Hmmm, I was only trying to use macros because I thought what I was 
trying wasn't possible with functions. Would this be a more appropriate 
approach?

(defun my-add-hook (hook &rest body)
   (add-hook (intern (concat (symbol-name hook) "-mode-hook"))
             `(lambda () ,@body)))

and then call it like:

(my-add-hook 'lisp-interaction
              '(my-translate-paren-types)
              '(imenu-add-to-menubar "Symbols")
              )

This seems a little more verbose with all the quotes, but I guess it 
could be the 'better' approach since it avoids using macros.

Perhaps my macro approach was a crock. The only reason I defended it was 
becuase I thought you meant that creating the my-add-hook functionality 
itself was the crock.

Well, I'm going with functions now, and I'm also going to get back to 
reading Paul Graham's 'On Lisp', the only comprehensive lisp macros book 
I know of (are there others?)

Lowell


David Kastrup wrote:

> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
> 
> 
>>This still doesn't seem to work. With the following defun and call:
>>
>>(defmacro my-add-hooks (hooks &rest body)
>>   `(dolist (hook ',hooks)
>>      (my-add-hook hook ,@body)))
>>
>>(my-add-hooks (inferior-lisp lisp emacs-lisp lisp-interaction)
>>               (imenu-add-to-menubar "Symbols"))
>>
>>I get the following macroexpansion, which looks correct to me, but
>>doesn't actually do anything:
>>
>>(cl-block-wrapper
>>  (catch (quote --cl-block-nil--)
>>    (let ((--dolist-temp--20870 (quote (inferior-lisp lisp emacs-lisp
>>    lisp-interaction)))
>>          hook)
>>      (while --dolist-temp--20870
>>        (setq hook (car --dolist-temp--20870))
>>        (my-add-hook hook
>>                     (imenu-add-to-menubar "Symbols"))
>>        (setq --dolist-temp--20870 (cdr --dolist-temp--20870)))
>>      nil)))
> 
> 
> That's because my-add-hook is a macro, too, and so you just add stuff
> to hook-mode-hook three times.
> 
> 
>>>Apart from that, I consider this sort of thing a crock.  What are
>>>you hoping to achieve that you would not be better off doing by a
>>>proper function instead of a macro?
> 
> 
> In short, I still consider this sort of thing a crock, since you'd be
> better off using a function instead of a macro.  You are unable to
> comprehend what your macros do, and it shows.  Macros are just not
> sensible for this sort of thing.  Use functions instead.  You'll need
> to use some quotes at the outer level, but you'll understand what
> happens.
> 
> To fix the above, you'd need to write something like
> 
> (defmacro my-add-hooks (hooks &rest body)
>    (dolist (hook hooks)
>       `(my-add-hook ,hook ,@body)))
> 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-27  8:10         ` Lowell Kirsh
@ 2004-07-27 12:05           ` Pascal Bourguignon
  2004-07-28  5:03             ` Rob Warnock
  2004-07-31 20:46             ` Lowell Kirsh
  0 siblings, 2 replies; 33+ messages in thread
From: Pascal Bourguignon @ 2004-07-27 12:05 UTC (permalink / raw)



Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

> Hmmm, I was only trying to use macros because I thought what I was
> trying wasn't possible with functions. Would this be a more
> appropriate approach?
> 
> (defun my-add-hook (hook &rest body)
>    (add-hook (intern (concat (symbol-name hook) "-mode-hook"))
>              `(lambda () ,@body)))
> 
> and then call it like:
> 
> (my-add-hook 'lisp-interaction
>               '(my-translate-paren-types)
>               '(imenu-add-to-menubar "Symbols")
>               )
> 
> This seems a little more verbose with all the quotes, but I guess it
> could be the 'better' approach since it avoids using macros.
> 
> Perhaps my macro approach was a crock. The only reason I defended it
> was becuase I thought you meant that creating the my-add-hook
> functionality itself was the crock.

There is no fundamental difference between a function and a macro.
The only difference, is that functions are called at so called
"run-time" while macros are called at so called "compilation-time".

Now, think about it, when you're using actually a lisp interpreter,
when is "run-time", and when is "compilation-time"?  (You can check
CLHS to see how Common-Lisp  defines these "times").


[There's also the little difference that macro lambda list may involve
destructuring of arguments, while function lambda list don't and
function must do it explicitely with DESTRUCTURE-BIND. But let's
ignore this detail for now.  In lisp that are lexically scoped like
Common-Lisp, there's also that little impact, that scopes can be
modified only at "compilation-time", not anymore at "run-time". So
you'd HAVE to use a macro to process scopes and lexical bindings as
first class objects in lexically scoped lisps.  But since emacs lisp
is not lexically scoped, this difference does not even matter.]


Let's consider a simple macro:

(defmacro myif (condition then &optional else)
   `(cond (,condition ,then)
          (t          ,else)))

(macroexpand-1 '(myif (= a b) 0 (- a b))) --> (COND ((= A B) 0) (T (- A B))) ; T


To see how one can  generate an equivalent function, let's use this
macro:

(defmacro functionify-macro (defmacro-sexp) 
  ;; Naive implementation, for pedagogical purposes only.
  ;; Lacks smart handling of lambda lists...
  (let ((fun (intern (concatenate 'string 
                       (string (second defmacro-sexp)) "-FUN"))))
    `(progn
       (defun ,fun
         ,@(cddr defmacro-sexp))
       (defmacro ,(second defmacro-sexp) ,(third defmacro-sexp)
         (,fun ,@(mapcan (lambda (arg) 
                           (cond 
                            ((listp arg) (list (first arg)))
                            ((char= (character "&") (aref (string arg) 0))
                             nil)
                            ((symbolp arg) (list arg))
                            (t (error "Bad argument"))))
                         (third defmacro-sexp)))))))

(macroexpand-1 '(functionify-macro
                 (defmacro if (condition then &optional else)
                   `(cond (,condition ,then)
                          (t          ,else)))))

--> (PROGN
     (DEFUN IF-FUN (CONDITION THEN &OPTIONAL ELSE)
      `(COND (,CONDITION ,THEN) (T ,ELSE)))
     (DEFMACRO IF (CONDITION THEN &OPTIONAL ELSE) 
         (IF-FUN CONDITION THEN ELSE)))   ; T

So, the macro just calls the function with exactly the same arguments.
Well, "exactly", not exactly, because if that little difference
between "compilation-time" and "run-time", when you invoke a macro,
the arguments are not evalued, but when you call a function they are.
Only that since the macro already has the arguments unevalued, what
they are are literal sexps, not mere values, so when the macro calls
the function, the arguments evaluate (at "compilation-time", remember
the macro executes at "compilation-time", to themselves, and the
function (called by the macro) executed at "compilation-time" will get
literal sexps as arguments.  That's why it'll be able to do the exact
same job as the macro;


(functionify-macro
 (defmacro myif (condition then &optional else)
   `(cond (,condition ,then)
          (t          ,else))))


(macroexpand-1 '(myif (= a b) 0 (- a b))) --> (COND ((= A B) 0) (T (- A B))) ; T
(myif-fun '(= a b) '0 '(- a b))           --> (COND ((= A B) 0) (T (- A B)))


Macros are more difficult to use "programmatically", that is, if you
don't know the exact value of the arguments at "compilation-time",
it's harder to use a macro (you'd have to use eval and have other
difficulties). That's why often you find that a defmacro is just a
thin layer over a function, so you can use the macro at
"compilation-time", and the function at "run-time". [See also the
difference between CLOS (defclass, defmethod MACROS) and MOP
(add-direct-subclass, add-method FUNCTIONS)].


Now, to come back to your problem,

 ;; a function:
 (add-hook-to-mode 'test  
    '(message "test mode hook")
    '(message "first hook"))

or:

  ;; a macro:
  (add-hook-to-mode test 
     (message "test mode hook")
     (message "first hook"))

I don't see the point, compared to: 

    (add-hook 'test-mode-hook
        (lambda () 
            (message "test mode hook")
            (message "first hook")))


Anyway, if you insist on your function, you can always use progn to
minimize the number of quotes:

  (add-hook-to-mode 'test 
     '(progn (message "test mode hook")
             (message "first hook")))



> Well, I'm going with functions now, and I'm also going to get back to
> reading Paul Graham's 'On Lisp', the only comprehensive lisp macros
> book I know of (are there others?)

Beware that when you have a hammer in the hand, 
everything looks like a nail!


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-27  7:14       ` David Kastrup
  2004-07-27  8:10         ` Lowell Kirsh
@ 2004-07-27 23:22         ` Barry Fishman
  1 sibling, 0 replies; 33+ messages in thread
From: Barry Fishman @ 2004-07-27 23:22 UTC (permalink / raw)


David Kastrup <dak@gnu.org> writes:

> Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
>
>> This still doesn't seem to work. With the following defun and call:
>> 
>> (defmacro my-add-hooks (hooks &rest body)
>>    `(dolist (hook ',hooks)
>>       (my-add-hook hook ,@body)))
>> 
>> (my-add-hooks (inferior-lisp lisp emacs-lisp lisp-interaction)
>>                (imenu-add-to-menubar "Symbols"))
>> 
>> > you hoping to achieve that you would not be better off doing by a
>> > proper function instead of a macro?
>
> In short, I still consider this sort of thing a crock, since you'd be
> better off using a function instead of a macro.  You are unable to
> comprehend what your macros do, and it shows.  Macros are just not
> sensible for this sort of thing.  Use functions instead.  You'll need
> to use some quotes at the outer level, but you'll understand what
> happens.
>
> To fix the above, you'd need to write something like
>
> (defmacro my-add-hooks (hooks &rest body)
>    (dolist (hook hooks)
>       `(my-add-hook ,hook ,@body)))


The body of the defmacro has to return some code.  The dolist
will return just NIL.

Assuming that you want my-add-hooks to create a series of my-add-hook
calls, one would need something like:

(defmacro my-add-hooks (hooks &rest body)
   (cons 'progn (mapcar (lambda (h) `(my-add-hook ,h ,@body)) hooks)))

Its usually easier to do the work in a function and use a macro to
create the syntax you want.  For example, using a function like:

(defun my-add-hooks-fn (hooks func)
  (dolist (hook hooks)
    (add-hook (intern (concat (symbol-name hook) "-mode-hook")) func)))

One can give it the syntax you want with a macro like:

(defmacro my-add-hooks (hooks &rest body)
  `(my-add-hooks-2 ',hooks (lambda () ,@body)))

This has the advantage of creating a single lambda function rather
than multiple lambda functions with the same contents.

This also allows one to build a more complex my-add-hooks-fn without
dealing with the extra complexity of structuring it as a macro.

-- 
Barry Fishman

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-27 12:05           ` Pascal Bourguignon
@ 2004-07-28  5:03             ` Rob Warnock
  2004-07-31 20:46             ` Lowell Kirsh
  1 sibling, 0 replies; 33+ messages in thread
From: Rob Warnock @ 2004-07-28  5:03 UTC (permalink / raw)


Pascal Bourguignon  <spam@thalassa.informatimago.com> wrote:
+---------------
| There is no fundamental difference between a function and a macro.
| The only difference, is that functions are called at so called
| "run-time" while macros are called at so called "compilation-time".
| 
| Now, think about it, when you're using actually a lisp interpreter,
| when is "run-time", and when is "compilation-time"?  (You can check
| CLHS to see how Common-Lisp  defines these "times").
+---------------

Minor quibble: A macro-function gets called at "macro expansion time",
which can be either during compilation (see CLHS "3.2.2.2 Minimal
Compilation") or evaluation (CLHS "3.1.2.1.2.2 Macro Forms").

Whether the top-level interactive REPL provides at least "minimal
compilation" or not is an implementation decision. SBCL always does
full compilation (IIUC), whereas CMUCL does only minimal compilation of
interpreted forms, and at that not until the first time the form is
evaluated (by which I'm specifically referring to the body forms of a
function typed to the REPL), for example:

    cmu> (defmacro say-expand (tag)
	   (format t "I'm expanding here: ~s~%" tag)
	   'nil)

    SAY-EXPAND
    cmu> (defun foo ()
	   (say-expand in-foo)
	   37)

    FOO
    cmu> (foo)
    I'm expanding here: IN-FOO
    37
    cmu> (foo)

    37
    cmu> 


-Rob

p.s. Other things besides calling a function can cause its body to
be minimally-compiled in CMUCL, e.g., if right after the definition
of FOO above you called DESCRIBE on it:

    cmu> (describe 'foo)

    FOO is an internal symbol in the COMMON-LISP-USER package.
    Function: #<Interpreted Function FOO {488FD8B1}>
    Function arguments:
      There are no arguments.I'm expanding here: IN-FOO     [ <== LOOK! ]
    Its defined argument types are:
      NIL
    Its result type is:
      *
    Its definition is:
      (LAMBDA () (BLOCK FOO # 37))
    cmu> (foo)

    37
    cmu> 

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-27 12:05           ` Pascal Bourguignon
  2004-07-28  5:03             ` Rob Warnock
@ 2004-07-31 20:46             ` Lowell Kirsh
  2004-08-03 18:44               ` Michael Slass
  1 sibling, 1 reply; 33+ messages in thread
From: Lowell Kirsh @ 2004-07-31 20:46 UTC (permalink / raw)


By the way, I never mentioned this, but I broke my wrist pretty badly 
and that's why I'm trying so hard to save keystrokes. It seems like it 
might not have been worth the effort, but it's definitely been a 
learning experience anyway.

Lowell

> Now, to come back to your problem,
> 
>  ;; a function:
>  (add-hook-to-mode 'test  
>     '(message "test mode hook")
>     '(message "first hook"))
> 
> or:
> 
>   ;; a macro:
>   (add-hook-to-mode test 
>      (message "test mode hook")
>      (message "first hook"))
> 
> I don't see the point, compared to: 
> 
>     (add-hook 'test-mode-hook
>         (lambda () 
>             (message "test mode hook")
>             (message "first hook")))

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: elisp macros problem
  2004-07-31 20:46             ` Lowell Kirsh
@ 2004-08-03 18:44               ` Michael Slass
  0 siblings, 0 replies; 33+ messages in thread
From: Michael Slass @ 2004-08-03 18:44 UTC (permalink / raw)


Lowell Kirsh <lkirsh@cs.ubc.ca> writes:

>By the way, I never mentioned this, but I broke my wrist pretty badly and
>that's why I'm trying so hard to save keystrokes. It seems like it might
>not have been worth the effort, but it's definitely been a learning
>experience anyway.
>

You'll definitely want to check out this guy's site, then:
http://www.cb1.com/~john/computing/emacs/handsfree/pedals.html

-- 
Mike Slass

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2004-08-03 18:44 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-24 18:39 elisp macros problem Lowell Kirsh
2004-07-24 19:00 ` David Kastrup
2004-07-24 22:08   ` Lowell Kirsh
2004-07-24 23:41     ` David Kastrup
2004-07-25  1:58       ` Lowell Kirsh
2004-07-25 10:59         ` Kalle Olavi Niemitalo
2004-07-24 19:15 ` Barry Margolin
2004-07-24 19:59   ` Pascal Bourguignon
2004-07-24 20:50     ` David Kastrup
2004-07-24 21:49       ` Lowell Kirsh
2004-07-26  1:35 ` Lowell Kirsh
2004-07-26  1:55   ` Rahul Jain
2004-07-26  2:53     ` Lowell Kirsh
2004-07-26  4:05       ` Pascal Bourguignon
2004-07-26  4:13         ` Lowell Kirsh
2004-07-26  2:54     ` Lowell Kirsh
2004-07-26 22:16       ` Kalle Olavi Niemitalo
2004-07-26 22:58       ` Kevin Rodgers
2004-07-26  2:03   ` Barry Margolin
2004-07-26  3:06     ` Lowell Kirsh
2004-07-26  4:49       ` Barry Margolin
2004-07-26  5:20         ` Pascal Bourguignon
2004-07-26  6:10       ` Oliver Scholz
2004-07-26  5:55   ` David Kastrup
2004-07-27  6:38     ` Lowell Kirsh
2004-07-27  6:54     ` Lowell Kirsh
2004-07-27  7:14       ` David Kastrup
2004-07-27  8:10         ` Lowell Kirsh
2004-07-27 12:05           ` Pascal Bourguignon
2004-07-28  5:03             ` Rob Warnock
2004-07-31 20:46             ` Lowell Kirsh
2004-08-03 18:44               ` Michael Slass
2004-07-27 23:22         ` Barry Fishman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).