From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: How do you pre-evaluate a function passed to a macro? Date: Fri, 13 Nov 2009 12:01:48 -0500 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1258134035 12677 80.91.229.12 (13 Nov 2009 17:40:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 13 Nov 2009 17:40:35 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 13 18:40:29 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N908L-0001rq-DX for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Nov 2009 18:40:29 +0100 Original-Received: from localhost ([127.0.0.1]:45224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N908L-0003ic-0p for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Nov 2009 12:40:29 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.mixmin.net!feeder.eternal-september.org!eternal-september.org!barmar.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 54 Original-X-Trace: news.eternal-september.org U2FsdGVkX18mB4V6JBDnVY/YvbiOCzKSx7iPTYNaB1AEXOuyyQ/oCwujtuoMEoLxitjqt+pvp1MdzTTMzEQlL4uG+jKNgqq7Tk37VTEFChtbNUomu7HPTSOnhR8OGfVZEIOJX2aiWbQ= Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Fri, 13 Nov 2009 17:01:48 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Auth-Sender: U2FsdGVkX19LloNSctCYRaNRwHYeO5YMYFeqESt2SWI= Cancel-Lock: sha1:sPwuXDKQw8Fq1M0Qf80v/NWOHxI= Original-Xref: news.stanford.edu gnu.emacs.help:174646 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69716 Archived-At: In article , 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 ***