From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: How do you pre-evaluate a function passed to a macro?
Date: Fri, 13 Nov 2009 12:01:48 -0500 [thread overview]
Message-ID: <barmar-F05197.12014813112009@news.eternal-september.org> (raw)
In-Reply-To: mailman.10640.1258121962.2239.help-gnu-emacs@gnu.org
In article <mailman.10640.1258121962.2239.help-gnu-emacs@gnu.org>,
gregory@dynapse.com (Gregory J. Grubbs) wrote:
> I'm calling a function, wanting to pass nil instead of the empty string
> when the string argument is zero length. But the function is defined as
> a macro, so the argument gets passed in unevaluated, which fails.
>
> How do I force evaluation of the argument before it is passed in?
Use eval:
(eval `(bbdb-search (bbdb-records)
',(if (> (length myname) 0) myname nil)
nil nil))
>
> --8<---------------cut here---------------start------------->8---
> ;; myname is a string taken from user input
> (bbdb-search (bbdb-records) (if (> (length myname) 0) myname nil) nil nil)
> --8<---------------cut here---------------end--------------->8---
>
> The above call produces the following backtrace:
> --8<---------------cut here---------------start------------->8---
> signal(error ("name must be atomic"))
> error("name must be atomic")
> (or (stringp name) (symbolp name) (error "name must be atomic"))
> (let (clauses) (or (stringp name) (symbolp name) (error "name must be
> atomic")) (or (stringp company) (symbolp company) (error "company must be
> atomic")) (or (stringp net) (symbolp net) (error "net must be atomic")) (or
> (stringp notes) (symbolp notes) (error "notes must be atomic")) (or
> (stringp phone) (symbolp phone) (error "phone must be atomic")) (if phone
> (setq clauses ...)) (if notes (setq clauses ...)) (if name (setq clauses
> ...)) (if net (setq clauses ...)) (if company (setq clauses ...)) (\` (let
> ... ... ...)))
> (lambda (records &optional name company net notes phone) "Search RECORDS
> for optional arguments NAME, COMPANY, NET, NOTES, PHONE.\nThis macro only
> emits code for those things being searched for;\nliteral nils at
> compile-time cause no code to be emitted.\n\nIf you want to reverse the
> search, bind `bbdb-search-invert' to t." (let (clauses) (or ... ... ...)
> (or ... ... ...) (or ... ... ...) (or ... ... ...) (or ... ... ...) (if
> phone ...) (if notes ...) (if name ...) (if net ...) (if company ...) (\`
> ...)))((bbdb-records) (if (> (length myname) 0) myname nil) nil nil)
> (bbdb-search (bbdb-records) (if (> ... 0) myname nil) nil nil)
> eval((bbdb-search (bbdb-records) (if (> ... 0) myname nil) nil nil))
> eval-expression((bbdb-search (bbdb-records) (if (> ... 0) myname nil) nil
> nil) nil)
> call-interactively(eval-expression nil nil)
> --8<---------------cut here---------------end--------------->8---
--
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 ***
next parent reply other threads:[~2009-11-13 17:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.10640.1258121962.2239.help-gnu-emacs@gnu.org>
2009-11-13 17:01 ` Barry Margolin [this message]
2009-11-14 8:18 ` How do you pre-evaluate a function passed to a macro? Stefan Monnier
2009-11-13 14:18 Gregory J. Grubbs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=barmar-F05197.12014813112009@news.eternal-september.org \
--to=barmar@alum.mit.edu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.