I have a macro: mac1(&rest args) that accepts any number of arguments
Since I cannot use apply with a macro, and since I have no control on the macro's implementation, how can I make a function fun1 (lst) that given a list, calls the macro with the expanded list?
UPDATE: I though the question was adequate but it seems better to state my real case:
Postmodern provides the query macro:
macro: query (query &rest args/format)
For example you call it like this:
(query
"select * from example where col1 = $1::integer and col2 = $2::date"
123
"2017-01-01"
:str-alists)
Ok, now imagine that at runtime I am passed this list:
'((:query "select * from table1 where c1 = $1 and c2 = $2 and c3 = $3"
:params (1 "2017-01-01" 3) :return :str-alists
(:query "select * from tab2 where c3 = $1"
:params ("somevalue") :return :lists)
.
.
.
))
And I have to do the queries. I need to define a function that will take such a list as argument and do the queries. But since query is a macro I have the following problem: I need somewhere to evaluate the lists in order to pass them to the macro. Currently I am doing this (idea taken from @melpomene comments) :
(defun macro-apply(q p ret)
(eval (macroexpand `(query ,q ,@p ,ret))))
So the function becomes:
(defun exec-queries (lst)
(mapc
(lambda(x) (macro-apply
(getf x :query)
(getf x :params)
(getf x :return))
lst))
Is there a better way, or something obvious that I am missing?