all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: gregory@dynapse.com (Gregory J. Grubbs)
To: help-gnu-emacs@gnu.org
Subject: How do you pre-evaluate a function passed to a macro?
Date: Fri, 13 Nov 2009 07:18:44 -0700	[thread overview]
Message-ID: <87skcipkxn.fsf@dynapse.com> (raw)

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?

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





             reply	other threads:[~2009-11-13 14:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-13 14:18 Gregory J. Grubbs [this message]
     [not found] <mailman.10640.1258121962.2239.help-gnu-emacs@gnu.org>
2009-11-13 17:01 ` How do you pre-evaluate a function passed to a macro? Barry Margolin
2009-11-14  8:18 ` Stefan Monnier

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=87skcipkxn.fsf@dynapse.com \
    --to=gregory@dynapse.com \
    --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.