Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

macro

14 views
Skip to first unread message

Haris

unread,
Feb 12, 2011, 8:06:11 AM2/12/11
to
Hi.

How to repeat this piece of code with a macro:

,@(if (/= (length (parameter "ime")) 0) (list 'ime (parameter "ime")) (list
'ime :null))

while 'ime and "ime" changes while repeating.

That's already a part of a "sql-compile" macro, like this:

(sql-compile `(:insert-into 'kupci :set
,@(if (/= (length (parameter "ime")) 0) (list 'ime (parameter "ime")) (list
'ime :null))
,@(if (/= (length (parameter "prezime")) 0) (list 'prezime (parameter
"prezime")) (list 'prezime
and so on.

I should be able to call it like: (a-macro 'ime 'prezime ...)

Thanks

Pascal J. Bourguignon

unread,
Feb 12, 2011, 8:26:24 AM2/12/11
to
"Haris" <fbogd...@xnet.hr> writes:

> How to repeat this piece of code with a macro:
>
> ,@(if (/= (length (parameter "ime")) 0) (list 'ime (parameter "ime"))
> (list 'ime :null))

Hard to say, since this is NOT a piece of code.

,@ outside of ` is meaningless.

> while 'ime and "ime" changes while repeating.
>
> That's already a part of a "sql-compile" macro, like this:
>
> (sql-compile `(:insert-into 'kupci :set
> ,@(if (/= (length (parameter "ime")) 0) (list 'ime (parameter "ime"))
> (list 'ime :null))
> ,@(if (/= (length (parameter "prezime")) 0) (list 'prezime (parameter
> "prezime")) (list 'prezime
> and so on.
>
> I should be able to call it like: (a-macro 'ime 'prezime ...)

I can't see any reason why it should be a macro.

(defun generate-sql-set (parameter)
(let* ((name (string parameter))
(value (parameter name)))
(list parameter
(if (zerop (length value))
:null
value))))

(defun generate-sql-sets (parameters)
(reduce (function append) parameters
:key (function generate-sql-set)
:from-end t))

(sql-compile `(:insert-into 'kupci :set ,(generate-sql-sets '(ime prezime))))


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

0 new messages