help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Check if a symbol is bound to a macro


From: Barry Margolin
Subject: Re: Check if a symbol is bound to a macro
Date: Tue, 08 Dec 2009 15:52:54 -0500
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

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 ***


reply via email to

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