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

First macro

15 views
Skip to first unread message

Luke Crook

unread,
Jan 10, 2004, 6:04:36 AM1/10/04
to
I am attempting to write a macro that generates the clauses in a COND

I do this using a mapcar..

`(cond
,@(mapcar #'(lambda (event)
(cond
...))
list-of-events))

..passing it a list-of-events and having it generate the corresponding
clause..

`((eql

..based on a (COND). My problem is that the lambda will return NIL
when no clause is generated, obviously. mapcar then cons this result
onto the result list. This tends to mess up my COND, interspersing the
tests with NIL.

Is there an easy way I can have mapcar not add NIL to the list of
results ? Or have the lambda not return a nil ? Or am I approaching
this the wrong way ?

Wolfhard Buß

unread,
Jan 10, 2004, 9:49:18 AM1/10/04
to
MAPCLAN, a MAPCAR that doesn't cons nils, also known as MAPPEND, is
probably what you are looking for.

(defun mapclan (function list &rest lists)
(loop for args in (zip (cons list lists))
when (apply function args) collect it))

--
"Hurry if you still want to see something. Everything is vanishing."
-- Paul Cézanne (1839-1906)

Luke J Crook

unread,
Jan 11, 2004, 2:16:48 AM1/11/04
to
Wolfhard Buß wrote:
> MAPCLAN, a MAPCAR that doesn't cons nils, also known as MAPPEND, is
> probably what you are looking for.
>
> (defun mapclan (function list &rest lists)
> (loop for args in (zip (cons list lists))
> when (apply function args) collect it))
>

Thanks for the feedback. My post is actually a dupe, thanks to the delay
of a couple of days when I tried to post through google .

-Luke

0 new messages