all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* defmacro* usage
@ 2011-11-02 11:28 Thierry Volpiatto
  2011-11-02 13:02 ` Andreas Schwab
  2011-11-02 13:04 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Thierry Volpiatto @ 2011-11-02 11:28 UTC (permalink / raw)
  To: emacs-devel

Hi all,
I have an error with following recipe:

#+BEGIN_SRC lisp
(defmacro* test1 (&key (lang 'french))
  `(case ,lang
     (french (message "Bonjour"))
     (english (message "Hello"))))

(test1 :lang 'french)
"Bonjour"
(test1 :lang 'english)
"Hello"
(test1)
Debugger entered--Lisp error: (void-variable french)
  (eql french (quote french))
  (cond ((eql french (quote french)) (message "Bonjour")) ((eql french (quote english)) (message "Hello")))
  (case french (french (message "Bonjour")) (english (message "Hello")))
  (test1)
  eval((test1) nil)
  eval-last-sexp-1(t)
  eval-last-sexp(t)
  eval-print-last-sexp()
  call-interactively(eval-print-last-sexp nil nil)


(defun* test2 (&key (lang 'french))
  (case lang
     (french (message "Bonjour"))
     (english (message "Hello"))))

(test2 :lang 'french)
"Bonjour"
(test2 :lang 'english)
"Hello"
(test2)
"Bonjour"

#+END_SRC

As you can see, the quoted default argument 'french cause an error with
the defmacro* and work fine with the defun*.

Is it a bug or i misunderstand something?
Thanks.

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 




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

* Re: defmacro* usage
  2011-11-02 11:28 defmacro* usage Thierry Volpiatto
@ 2011-11-02 13:02 ` Andreas Schwab
  2011-11-02 13:04 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2011-11-02 13:02 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: emacs-devel

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> Is it a bug or i misunderstand something?

That appears to be how it works in CL.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: defmacro* usage
  2011-11-02 11:28 defmacro* usage Thierry Volpiatto
  2011-11-02 13:02 ` Andreas Schwab
@ 2011-11-02 13:04 ` Stefan Monnier
  2011-11-02 13:15   ` Thierry Volpiatto
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2011-11-02 13:04 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: emacs-devel

> I have an error with following recipe:

> #+BEGIN_SRC lisp
> (defmacro* test1 (&key (lang 'french))
>   `(case ,lang
>      (french (message "Bonjour"))
>      (english (message "Hello"))))
[...]
> As you can see, the quoted default argument 'french cause an error with
> the defmacro* and work fine with the defun*.

The error is not from defmacro* but from the code you generated using defmacro*.

> Is it a bug or i misunderstand something?

A misunderstanding.  Think harder about what your macro does.  E.g. try
(macroexpand '(test1 :lang 'toto)) and (macroexpand '(test1)).
During macroexpansion, your `lang' is not supposed to hold a "language
value" but "a Lisp expression that will evaluate to a language value".


        Stefan



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

* Re: defmacro* usage
  2011-11-02 13:04 ` Stefan Monnier
@ 2011-11-02 13:15   ` Thierry Volpiatto
  0 siblings, 0 replies; 4+ messages in thread
From: Thierry Volpiatto @ 2011-11-02 13:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> I have an error with following recipe:
>
>> #+BEGIN_SRC lisp
>> (defmacro* test1 (&key (lang 'french))
>>   `(case ,lang
>>      (french (message "Bonjour"))
>>      (english (message "Hello"))))
> [...]
>> As you can see, the quoted default argument 'french cause an error with
>> the defmacro* and work fine with the defun*.
>
> The error is not from defmacro* but from the code you generated using defmacro*.
>
>> Is it a bug or i misunderstand something?
>
> A misunderstanding.  Think harder about what your macro does.  E.g. try
> (macroexpand '(test1 :lang 'toto)) and (macroexpand '(test1)).
> During macroexpansion, your `lang' is not supposed to hold a "language
> value" but "a Lisp expression that will evaluate to a language value".
Ok, thanks for explanation.

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 



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

end of thread, other threads:[~2011-11-02 13:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-02 11:28 defmacro* usage Thierry Volpiatto
2011-11-02 13:02 ` Andreas Schwab
2011-11-02 13:04 ` Stefan Monnier
2011-11-02 13:15   ` Thierry Volpiatto

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.