* Strange behavior of macro
@ 2006-05-30 8:56 Herbert Euler
2006-05-30 9:34 ` David Kastrup
2006-05-30 10:23 ` Andreas Schwab
0 siblings, 2 replies; 5+ messages in thread
From: Herbert Euler @ 2006-05-30 8:56 UTC (permalink / raw)
Hello,
Is the following in Emacs a expected behavior of macro?
(defmacro m1 (v)
(let ((len (length (eval v))))
`(quote ,len)))
=> m1
(m1 '(1 2 3))
=> 3
(setq v1 '(1 2 3))
=> (1 2 3)
(m1 v1)
=> 3
(setq v v1)
=> (1 2 3)
(m1 v)
=> error: (wrong-type-argument sequencep v)
Thanks.
Regards,
Guanpeng Xu
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange behavior of macro
2006-05-30 8:56 Strange behavior of macro Herbert Euler
@ 2006-05-30 9:34 ` David Kastrup
2006-05-30 10:23 ` Andreas Schwab
1 sibling, 0 replies; 5+ messages in thread
From: David Kastrup @ 2006-05-30 9:34 UTC (permalink / raw)
Cc: emacs-devel
"Herbert Euler" <herberteuler@hotmail.com> writes:
> Is the following in Emacs a expected behavior of macro?
>
> (defmacro m1 (v)
> (let ((len (length (eval v))))
> `(quote ,len)))
> => m1
>
> (m1 '(1 2 3))
> => 3
>
> (setq v1 '(1 2 3))
> => (1 2 3)
>
> (m1 v1)
> => 3
>
> (setq v v1)
> => (1 2 3)
>
> (m1 v)
> => error: (wrong-type-argument sequencep v)
In combination with dynamic scope, yes. m1 gets passed 'v as v, so
now v is bound to 'v and (eval v) again delivers 'v.
Evaluating a macro argument in the macro itself is often asking for
trouble. And Elisp's scoping rules don't exactly help.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange behavior of macro
2006-05-30 8:56 Strange behavior of macro Herbert Euler
2006-05-30 9:34 ` David Kastrup
@ 2006-05-30 10:23 ` Andreas Schwab
2006-05-30 10:31 ` Herbert Euler
1 sibling, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2006-05-30 10:23 UTC (permalink / raw)
Cc: emacs-devel
"Herbert Euler" <herberteuler@hotmail.com> writes:
> Is the following in Emacs a expected behavior of macro?
>
> (defmacro m1 (v)
> (let ((len (length (eval v))))
> `(quote ,len)))
> => m1
[...]
> (m1 v)
> => error: (wrong-type-argument sequencep v)
See (elisp)Eval During Expansion.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange behavior of macro
2006-05-30 10:23 ` Andreas Schwab
@ 2006-05-30 10:31 ` Herbert Euler
2006-05-30 10:35 ` Andreas Schwab
0 siblings, 1 reply; 5+ messages in thread
From: Herbert Euler @ 2006-05-30 10:31 UTC (permalink / raw)
Cc: emacs-devel
>From: Andreas Schwab <schwab@suse.de>
>To: "Herbert Euler" <herberteuler@hotmail.com>
>CC: emacs-devel@gnu.org
>Subject: Re: Strange behavior of macro
>Date: Tue, 30 May 2006 12:23:49 +0200
>
>"Herbert Euler" <herberteuler@hotmail.com> writes:
>
> > Is the following in Emacs a expected behavior of macro?
> >
> > (defmacro m1 (v)
> > (let ((len (length (eval v))))
> > `(quote ,len)))
> > => m1
>[...]
> > (m1 v)
> > => error: (wrong-type-argument sequencep v)
>
>See (elisp)Eval During Expansion.
OK, so it's an accepted behavior. Btw, in the test of GNU clisp,
it's safe to write such a macro:
[1]> (defmacro m1 (v)
(let ((len (length (eval v))))
`(quote ,len)))
M1
[2]> (m1 '(1 2 3))
3
[3]> (setq v1 '(1 2 3))
(1 2 3)
[4]> (m1 v1)
3
[5]> (setq v v1)
(1 2 3)
[6]> (m1 v)
3
[7]>
Regards,
Guanpeng Xu
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Strange behavior of macro
2006-05-30 10:31 ` Herbert Euler
@ 2006-05-30 10:35 ` Andreas Schwab
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2006-05-30 10:35 UTC (permalink / raw)
Cc: emacs-devel
"Herbert Euler" <herberteuler@hotmail.com> writes:
>>From: Andreas Schwab <schwab@suse.de>
>>To: "Herbert Euler" <herberteuler@hotmail.com>
>>CC: emacs-devel@gnu.org
>>Subject: Re: Strange behavior of macro
>>Date: Tue, 30 May 2006 12:23:49 +0200
>>
>>"Herbert Euler" <herberteuler@hotmail.com> writes:
>>
>> > Is the following in Emacs a expected behavior of macro?
>> >
>> > (defmacro m1 (v)
>> > (let ((len (length (eval v))))
>> > `(quote ,len)))
>> > => m1
>>[...]
>> > (m1 v)
>> > => error: (wrong-type-argument sequencep v)
>>
>>See (elisp)Eval During Expansion.
>
> OK, so it's an accepted behavior. Btw, in the test of GNU clisp,
> it's safe to write such a macro:
Emacs Lisp is using dynamic binding, not lexical binding.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-05-30 10:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-30 8:56 Strange behavior of macro Herbert Euler
2006-05-30 9:34 ` David Kastrup
2006-05-30 10:23 ` Andreas Schwab
2006-05-30 10:31 ` Herbert Euler
2006-05-30 10:35 ` Andreas Schwab
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.