[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How do you pre-evaluate a function passed to a macro?
From: |
Gregory J. Grubbs |
Subject: |
How do you pre-evaluate a function passed to a macro? |
Date: |
Fri, 13 Nov 2009 07:18:44 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
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---
- How do you pre-evaluate a function passed to a macro?,
Gregory J. Grubbs <=