* Check if a symbol is bound to a macro
@ 2009-12-08 20:43 Nordlöw
2009-12-08 20:52 ` Barry Margolin
0 siblings, 1 reply; 3+ messages in thread
From: Nordlöw @ 2009-12-08 20:43 UTC (permalink / raw)
To: help-gnu-emacs
Is there a way to query if a symbol is bound to a macro?
list-fns.el written by Noah Friedman provides the function
(defun macrop (x)
"Return `t' if X is a macro, `nil' otherwise.
X may be a raw or byte-compiled macro. No attempt is made to
determine if
the macro is actually well-formed (i.e. syntactically valid)."
(cond ((not (consp x))
nil)
((eq (car x) 'macro)
(functionp (cdr x)))))
but it doesn't work for me.
(macrop 'case)
returns nil.
Thanks,
Nordlöw
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Check if a symbol is bound to a macro
2009-12-08 20:43 Check if a symbol is bound to a macro Nordlöw
@ 2009-12-08 20:52 ` Barry Margolin
2009-12-08 22:17 ` Nordlöw
0 siblings, 1 reply; 3+ messages in thread
From: Barry Margolin @ 2009-12-08 20:52 UTC (permalink / raw)
To: help-gnu-emacs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1037 bytes --]
In article
<b240c2eb-6d28-410a-aa2d-4ea28568585b@a32g2000yqm.googlegroups.com>,
Nordlöw <per.nordlow@gmail.com> wrote:
> Is there a way to query if a symbol is bound to a macro?
>
> list-fns.el written by Noah Friedman provides the function
>
> (defun macrop (x)
> "Return `t' if X is a macro, `nil' otherwise.
> X may be a raw or byte-compiled macro. No attempt is made to
> determine if
> the macro is actually well-formed (i.e. syntactically valid)."
> (cond ((not (consp x))
> nil)
> ((eq (car x) 'macro)
> (functionp (cdr x)))))
>
> but it doesn't work for me.
> (macrop 'case)
> returns nil.
>
> Thanks,
> Nordlöw
macrop expects the function, not the function name, as its argument. So
you need to do:
(defun named-macrop (symbol)
(and (fboundp symbol)
(macrop (symbol-function symbol))))
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Check if a symbol is bound to a macro
2009-12-08 20:52 ` Barry Margolin
@ 2009-12-08 22:17 ` Nordlöw
0 siblings, 0 replies; 3+ messages in thread
From: Nordlöw @ 2009-12-08 22:17 UTC (permalink / raw)
To: help-gnu-emacs
On Dec 8, 9:52 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article
> <b240c2eb-6d28-410a-aa2d-4ea285685...@a32g2000yqm.googlegroups.com>,
>
>
>
>
>
> Nordlöw <per.nord...@gmail.com> wrote:
> > Is there a way to query if a symbol is bound to a macro?
>
> > list-fns.el written by Noah Friedman provides the function
>
> > (defun macrop (x)
> > "Return `t' if X is a macro, `nil' otherwise.
> > X may be a raw or byte-compiled macro. No attempt is made to
> > determine if
> > the macro is actually well-formed (i.e. syntactically valid)."
> > (cond ((not (consp x))
> > nil)
> > ((eq (car x) 'macro)
> > (functionp (cdr x)))))
>
> > but it doesn't work for me.
> > (macrop 'case)
> > returns nil.
>
> > Thanks,
> > Nordlöw
>
> macrop expects the function, not the function name, as its argument. So
> you need to do:
>
> (defun named-macrop (symbol)
> (and (fboundp symbol)
> (macrop (symbol-function symbol))))
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
Thanks!
/Per Nordlöw
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-12-08 22:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-08 20:43 Check if a symbol is bound to a macro Nordlöw
2009-12-08 20:52 ` Barry Margolin
2009-12-08 22:17 ` Nordlöw
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).