Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!daemon From: miller@ACORN.CS.ROCHESTER.EDU (Brad Miller) Newsgroups: comp.lang.lisp Subject: Re: CL question - conditional list elements Message-ID: <6371@sol.ARPA> Date: 30 Jan 88 02:34:42 GMT Sender: daemon@cs.rochester.edu Lines: 54 Date: 28 Jan 88 11:13:45 GMT From: ok@quintus.UUCP (Richard A. O'Keefe) Here's the maybe-list macro I suggested as an answer. It has the same properties as the Pop version. (Note that as in my maybe-cons, I assume that the thing is defined in my: package and that my:R is not exported.) This has been tested (somewhat). (defmacro maybe-list (&rest L) `(let ((my:R '())) ,@(expand-maybe-list L))) (defun expand-maybe-list (L) (cond ((endp L) ; L = () nil) ((endp (cdr L)) ; L = (x) `((setq my:R (list ,(car L))))) ((eq (cadr L) ':if) ; L = (x :if y . z) `(,@(expand-maybe-list (cdddr L)) (if ,(caddr L) (setq my:R (cons ,(car L) my:R))))) (t ; L = (x y . z) `(,@(expand-maybe-list (cdr L)) (setq my:R (cons ,(car L) my:R)))))) ;;; Example (it prints (A B E F)): (print (maybe-list 'a 'b :if T 'c :if NIL 'd :if NIL 'e :if T 'f )) possibly more true to the original syntax would be: (let (foo) (push 'a foo) (if condition (push 'b foo)) foo) and similarly could be marcoized if desired... if the original order is needed, return (nreverse foo) instead of foo... Besides, who cares about efficiency? THe compiler is supposed to worry about that not the programmer... (only 1/4 :-)) ------ miller@cs.rochester.edu {...allegra!rochester!miller} Brad Miller University of Rochester Computer Science Department 'If anything is True, this is.'